Thursday, April 15, 2010

Run stored proc using cmd.Parameters.AddWithValue C#

void

crtaspdotcustMsg()

{

SqlConnection myConnection = new SqlConnection(ConnectionString);

//string strSQL = "jde_rk.dbo.lins_CustomerMsg '" + @Email + "','" + Txtfn.Text + "','" + txtLnam.Text + "','" + Txtphno.Text + "','" + TextBox12.Text + "','" + TextBox10.Text + "','" + Session["Usrid"] + "','" + 11 + "'";

string strSQL = "jde_rk.dbo.lins_CustomerMsg ";

SqlCommand cmd = new SqlCommand(strSQL, myConnection);

cmd.CommandType =

CommandType.StoredProcedure;

cmd.Parameters.AddWithValue(

"@Email", Txtemail.Text);

cmd.Parameters.AddWithValue(

"@Firstname", Txtfn.Text);

cmd.Parameters.AddWithValue(

"@Lastname", txtLnam.Text);

cmd.Parameters.AddWithValue(

"@Phone", Txtphno.Text);

cmd.Parameters.AddWithValue(

"@PHSUB", TextBox12.Text);

cmd.Parameters.AddWithValue(

"@PHMSG", TextBox10.Text);

cmd.Parameters.AddWithValue(

"@PHUSER", Session["Usrid"]);

cmd.Parameters.AddWithValue(

"@CustomerID", 111);

myConnection.Open();

cmd.ExecuteNonQuery();

myConnection.Close();

}

No comments: