我可以在我的程序中执行删除,插入和更新,并尝试通过从我的数据库中调用创建的存储过程来执行插入操作.
这个按钮插件我工作得很好.
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);
}
Run Code Online (Sandbox Code Playgroud)
这是调用名为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);
}
Run Code Online (Sandbox Code Playgroud)