12. Understanding .NET Data Provider Connectivity : .NET Data Provider Classes : IngresParameter Class : Named Parameters Example
 
Share this page                  
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();