How do I take a query like:
"string strOleDb = "Select * from ProjectTable WHERE ID = 4";
and pass in an integer variable for the ID, instead of the literal 4?
Thanks always,
-Tim Sprout
Jon Skeet [C# MVP] - 28 Jun 2007 14:58 GMT
> How do I take a query like:
>
> "string strOleDb = "Select * from ProjectTable WHERE ID = 4";
>
> and pass in an integer variable for the ID, instead of the literal 4?
See the example in the OleDbParameter class documentation.
Jon
Ignacio Machin ( .NET/ C# MVP ) - 28 Jun 2007 15:31 GMT
Hi,
> How do I take a query like:
>
> "string strOleDb = "Select * from ProjectTable WHERE ID = 4";
>
> and pass in an integer variable for the ID, instead of the literal 4?
Replace with the correct classes:
using (SqlConnection con = new
SqlConnection(ConfigOptions.ConnectionString))
{
con.Open();
using (SqlCommand com = new SqlCommand())
{
com.CommandText = "InsertOffer";
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.Parameters.Add("@offerID", SqlDbType.Int).Value =
offerId;
com.ExecuteNonQuery();
}
}