ADO.NET parameters in SQL Server
The syntax of a SQL Server parameter uses a "@" symbol prefix on the parameter name as shown below:C# .NET
// Define the SQL Server command to get the product having the ID = 100...
SqlCommand command = new SqlCommand();
command.CommandText = "SELECT * FROM Product WHERE Product.ID=@PROD_ID";
command.Parameters.Add(new SqlParameter("@PROD_ID", 100));
// Execute the SQL Server command...
SqlDataReader reader = command.ExecuteReader();
DataTable tblProducts = new DataTable();
tblProducts.Load(reader);
foreach (DataRow rowProduct in tblProducts.Rows)
{
// Use the data...
}
ADO.NET parameters in MySQL
The syntax of a MySQL parameter uses a "?" symbol prefix on the parameter name as shown below:C# .NET
// Define the MySQL command to get the product having the ID = 100...
MySqlCommand command = new MySqlCommand();
command.CommandText = "SELECT * FROM Product WHERE Product.ID=?PROD_ID";
command.Parameters.Add(new MySqlParameter("?PROD_ID", 100));
// Execute the MySql command...
MySqlDataReader reader = command.ExecuteReader();
DataTable tblProducts = new DataTable();
tblProducts.Load(reader);
foreach (DataRow rowProduct in tblProducts.Rows)
{
// Use the data...
}
ADO.NET parameters in Oracle
The syntax of an Oracle parameter uses a ":" symbol prefix on the parameter name as shown below:C# .NET
// Define the Oracle command to get the product having the ID = 100...
OracleCommand command = new OracleCommand();
command.CommandText = "SELECT * FROM Product WHERE Product.ID=:PROD_ID";
command.Parameters.Add(new OracleParameter(":PROD_ID", 100));
// Execute the Oracle command...
OracleDataReader reader = command.ExecuteReader();
DataTable tblProducts = new DataTable();
tblProducts.Load(reader);
foreach (DataRow rowProduct in tblProducts.Rows)
{
// Use the data...
}
1 comment:
Thank you. It's good to see everything on one place.
Post a Comment