使用c#中的参数调用存储过程
private void btnAdd_Click(object sender, EventArgs e){ SqlConnection con = new SqlConnection(dc.Con); SqlCommand cmd = new SqlCommand("Command String", con); da.InsertCommand = new SqlCommand("INSERT INTO tblContacts VALUES (@FirstName, @LastName)", con); da.InsertCommand.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text; da.InsertCommand.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text; con.Open(); da.InsertCommand.ExecuteNonQuery(); con.Close(); dt.Clear(); da.Fill(dt); }
sp_Add_contact
sp_Add_contact(@FirstName,@LastName)
private void button1_Click(object sender, EventArgs e){ SqlConnection con = new SqlConnection(dc.Con); SqlCommand cmd = new SqlCommand("Command String", con); cmd.CommandType = CommandType.StoredProcedure; ??? con.Open(); da. ???.ExecuteNonQuery(); con.Close(); dt.Clear(); da.Fill(dt); }
四季花海
慕尼黑8549860
相关分类