Wednesday, June 11, 2008

Insert Data in C# asp.net by using stored proc.

Inserting Data in C# asp.net by using stored proc sql-server .


protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
string strSQL;
strSQL = "xxxx_Ins_yyyy";
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@fname", fname.Text);
cmd.Parameters.AddWithValue("@lname", lname.Text);
cmd.Parameters.AddWithValue("@Address", Address.Text);
cmd.Parameters.AddWithValue("@zip", zip.Text);
cmd.Parameters.AddWithValue("@dphone", dphone.Text);
cmd.Parameters.AddWithValue("@ephone", fname.Text);
cmd.Parameters.AddWithValue("@emailid", fname.Text);
cmd.Parameters.AddWithValue("@UpDated", System.DateTime.Now);
myConnection.Open();
cmd.ExecuteNonQuery();
myConnection.Close();
}
private string ConnectionString
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings"ConnectionString"].ConnectionString;
return connectionString;
}
}

www.visli.com

No comments: