menu

Blazor

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class NamedParameterSql - Blazor API Reference | Syncfusion

    Show / Hide Table of Contents

    Class NamedParameterSql

    This interface defines the properties necessary to execute a parameterized SQL query. It encapsulates the parameters and their values, enabling secure and efficient database operations.

    Inheritance
    System.Object
    NamedParameterSql
    Namespace: Syncfusion.Blazor.QueryBuilder
    Assembly: Syncfusion.Blazor.dll
    Syntax
    public class NamedParameterSql : Object
    Remarks

    Implementations of this interface should ensure that parameterized queries are constructed correctly to prevent SQL injection attacks. Parameterized SQL queries allow for the separation of SQL code from user input, thereby reducing the risk of malicious SQL injection attacks. For example, consider the following parameterized SQL query in C#:

    using System.Data.SqlClient;
    
    Define the SQL query with parameters
    string queryString = "SELECT * FROM Users WHERE Username = @Username AND Password = @Password"; ///
    Establish connection and command objects
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
    SqlCommand command = new SqlCommand(queryString, connection);
    
    Set parameter values
    command.Parameters.AddWithValue("@Username", username);
    command.Parameters.AddWithValue("@Password", password);
    
    Execute the query
    connection.Open();
    SqlDataReader reader = command.ExecuteReader(); /// while (reader.Read())
    {
    Process results 
    }
    }

    In the above example, '@Username' and '@Password' are placeholders for the actual values of the username and password provided by the user. These placeholders are replaced with the user-supplied values at runtime. This approach mitigates the risk of SQL injection attacks since the user input is treated as data rather than executable SQL code.

    Constructors

    NamedParameterSql()

    Declaration
    public NamedParameterSql()

    Properties

    Params

    Specifies the bind variable names from the SQL string to the associated values.

    Declaration
    public Dictionary<string, object> Params { get; set; }
    Property Value
    Type
    System.Collections.Generic.Dictionary<System.String, System.Object>

    Sql

    Defines the SQL WHERE clause with bind variable placeholders for each value.

    Declaration
    public string Sql { get; set; }
    Property Value
    Type
    System.String
    Remarks

    Using bind variable placeholders helps in separating SQL logic from data, enhancing security by preventing SQL injection attacks.

    string sql = “SELECT * FROM Users WHERE Username = ? AND Password = ?”;
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved