9. Understanding .NET Data Provider Connectivity : .NET Data Provider Classes : IngresParameter Class
 
Share this page                  
IngresParameter Class
The IngresParameter class represents a parameter for an IngresCommand for each question mark (?) placeholder in the command and, optionally, its mapping to a DataSet column.
The IngresParameter constructor determines the data type of the parameter in the following ways:
The constructor specifies an IngresType enumeration
The constructor specifies a System.DbType enumeration
Through the .NET Framework System.Type of the Value object if no specific data type is in the constructor
Positional Parameters
The data provider supports the positional (unnamed) parameter marker placeholder syntax using the question mark character (?) similar to ODBC and JDBC. Parameter data is accessed from the IngresParameterCollection in the same relative order as the parameter markers in the SQL statement.
Named Parameters
The data provider supports named parameters. A named parameter marker is constructed by an initial character of question mark (?), at-sign (@), or colon (:) followed by a name. The name is an alphanumeric identifier or an integer. Databases vary in the use of the initial character for a named parameter. While the Ingres recommended initial parameter marker character is the question mark, the .NET Data Provider supports all three characters.
If one parameter is named then all of the parameters must be named. If one parameter is unnamed (positional) then all of the parameters must be unnamed. For the sake of code readability, a mix of named parameters and unnamed parameters is not permitted.
For the sake of code readability, a mix of named parameters, each with a different initial parameter marker character in a single SQL statement is also not permitted.
Multiple occurrences of the same named parameter marker in the SQL statement is permitted.
Excess named parameters that are not referenced in the SQL statement are permitted in the IngresParameterCollection and are ignored.
The name comparison between the named parameter marker in the SQL statement and the named parameter in the IngresParameterCollection is not case sensitive.
Named Parameters Example
The following is an example of using named parameters:
cmd = conn.CreateCommand();
cmd.CommandText =
      "insert into mytable values ( ?key, ?col1 ?col2 ?col3 )";
cmd.Parameters.AddWithValue("?key", mykey);
cmd.Parameters.AddWithValue("?col3", mystring3);
cmd.Parameters.AddWithValue("?col1", mystring1);
cmd.Parameters.AddWithValue("?col2", mystring2);
cmd.ExecuteNonQuery();
 
cmd = conn.CreateCommand
cmd.CommandText =
      "insert into mytable values ( @key, @col1 @col2 @col3 )";
cmd.Parameters.AddWithValue("@key", mykey);
cmd.Parameters.AddWithValue("@col3", mystring3);
cmd.Parameters.AddWithValue("@col1", mystring1);
cmd.Parameters.AddWithValue("@col2", mystring2);
cmd.ExecuteNonQuery();
 
cmd = conn.CreateCommand();
cmd.CommandText =
      "insert into mytable values ( :key, :col1 :col2 :col3 )";
cmd.Parameters.AddWithValue(":key", mykey);
cmd.Parameters.AddWithValue(":col3", mystring3);
cmd.Parameters.AddWithValue(":col1", mystring1);
cmd.Parameters.AddWithValue(":col2", mystring2);
cmd.ExecuteNonQuery();
IngresParameter Class Example
The following is an implementation of the IngresParameter class:
static string DemoParameterSSN(
    string connstring, int intNumber, string strSSN)
{
    IngresConnection conn = new IngresConnection(connstring);
 
 
    string strName = null;
 
    conn.Open();
 
    IngresCommand cmd = new IngresCommand(
        "select name from demo_personnel where number = ? and ssn = ?",
        conn);
 
    // add two parameters to the command's IngresParameterCollection
    cmd.Parameters.Add(new IngresParameter("Number", intNumber));
    IngresParameter parm =
        new IngresParameter("SSN", IngresType.VarChar);
    parm.Value = strSSN;
    cmd.Parameters.Add(parm);
 
    IngresDataReader reader = cmd.ExecuteReader();
 
    while (reader.Read())
    {
        if (reader.IsDBNull(0))
            break;
        strName = reader.GetString(0);
    }
 
    reader.Close();
    conn.Close();
 
    return strName;
}
IngresParameter Class Declaration
The class declaration for IngresParameter class is:
C#: public sealed class IngresParameter : System.Data.Common.DbParameter, IDataParameter, IDbDataParameter, ICloneable
VB.NET: NotInheritable Public Class IngresParameter
Inherits System.Data.Common.DbParameter
Implements IDataParameter, IDbDataParameter, ICloneable
IngresParameter Class Properties
The properties for the IngresParameter are:
Property
Accessor
Description
DbType
get set
The type that the parameter must be converted to before being passed to the database server. Setting this parameter induces a setting of IngresType property.
Default is DbType.String.
Direction
get set
Indicators whether the parameter has an input, input/output, output, or procedure return value.
IngresType
get set
The type that the parameter must be converted to before being passed to the database server. Setting this parameter induces a setting of DbType property.
Default is IngresType.NvarChar if the database supports Unicode UTF-16; otherwise the default is IngresType.VarChar.
IsNullable
get set
Indicates whether the parameter accepts null values.
True = accepts null values. False = does not accept null values.
ParameterName
get set
The name of the parameter.
Default is “”.
Precision
get set
Maximum number of digits for decimal parameters.
Default is 0.
Scale
get set
Number of decimal places for decimal parameters.
Default is 0.
Size
get set
Maximum size of binary and string data to be sent to the server.
Default is inferred from the parameter value.
SourceColumn
get set
The name of the source column mapped to a DataSet.
Default is “”.
SourceVersion
get set
The DataRowVersion used by an UpdateCommand during an Update operation for setting the parameter.
Default is DataRowVersion.Current.
Value
get set
The value of the parameter.
Default is null.
Important!  .NET strings are Unicode based. If the application is sending a Unicode string as a parameter to a database field that is ASCII char or varchar, the application can direct the data provider to coerce the Unicode string to an ASCII string on the client side by setting the parameter DbType property to DbType.AnsiString, or the IngresType property to IngresType.VarChar.
IngresParameter Class Public Methods
The public methods available for the IngresParameter class are:
Method
Description
ToString
The name of the parameter.
 
IngresParameter Class Constructors
The constructors available to the IngresParameter class are:
Constructor Overloads
Description
IngresParameter()
Instantiates a new instance of the IngresParameter class using default property values
IngresParameter
(string, DbType)
Instantiates a new instance of the IngresParameter class using the defined parameter name and DbType.
IngresParameter
(string, IngresType)
Instantiates a new instance of the IngresParameter class using the defined parameter name and IngresType.
IngresParameter
(string, object)
Instantiates a new instance of the IngresParameter class using the defined parameter name and System.Object. The DbType and IngresType are inferred from the .NET Type of the object.
IngresParameter
(string, DbType, string)
Instantiates a new instance of the IngresParameter class using the defined parameter name, DbType, and source column name.
IngresParameter
(string, IngresType, string)
Instantiates a new instance of the IngresParameter class using the defined parameter name, IngresType, and source column name.
IngresParameter
(string, DbType, int)
Instantiates a new instance of the IngresParameter class using the defined parameter name, DbType, and column size.
IngresParameter
(string, IngresType, int)
Instantiates a new instance of the IngresParameter class using the defined parameter name, IngresType, and column size.
IngresParameter
(string, DbType, int, string)
Instantiates a new instance of the IngresParameter class using the defined parameter name, DbType, column size, and source column name.
IngresParameter
(string, IngresType, int, string)
Instantiates a new instance of the IngresParameter class using the defined parameter name, IngresType, column size, and source column name.
IngresParameter
(string, DbType, int, ParameterDirection, bool, byte, byte, string, DataRowVersion, object)
Instantiates a new instance of the IngresParameter class using the defined parameter name, DbType, column size, parameter direction, boolean indication of whether or not the field can be null, precision, scale, source column name, DataRowVersion describing the version of a System.Data.DataRow, and the value of the object.
IngresParameter
(string, IngresType, int, ParameterDirection, bool, byte, byte, string, DataRowVersion, object)
Instantiates a new instance of the IngresParameter class using the defined parameter name, IngresType, column size, parameter direction, boolean indication of whether or not the field can be null, precision, scale, source column name, DataRowVersion describing the version of a System.Data.DataRow, and the value of the object.