Call a stored procedure with parameter in c#

前端 未结 7 822
闹比i
闹比i 2020-11-22 16:16

I can do a delete, insert and update in my program and I try to do an insert by call a created stored procedure from my database.

This a button insert I make work

相关标签:
7条回答
  • 2020-11-22 17:01

    You have to add parameters since it is needed for the SP to execute

    using (SqlConnection con = new SqlConnection(dc.Con))
    {
        using (SqlCommand cmd = new SqlCommand("SP_ADD", con))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@FirstName", txtfirstname.Text);
            cmd.Parameters.AddWithValue("@LastName", txtlastname.Text);
            con.Open();
            cmd.ExecuteNonQuery();
        }            
    }
    
    0 讨论(0)
提交回复
热议问题