private void btnInsert_Click(object sender, EventArgs e)
{
empCode = txtCode.Text;
empName = txtName.Text;
empCell = txtCell.Text;
empAddress = txtAddress.Text;
try
{
using (cmd = new SqlCommand(" empInsert ", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@empcode", SqlDbType.VarChar).Value = empCode;
cmd.Parameters.Add("@empname", SqlDbType.VarChar).Value = empName;
cmd.Parameters.Add("@empcell", SqlDbType.VarChar).Value = empCell;
cmd.Parameters.Add("@empaddress", SqlDbType.VarChar).Value = empAddress;
conn.Open();
cmd.ExecuteNonQuery();
}
MessageBox.Show("succesfully inserted", "Congrates");
}
catch (Exception ex)
{
MessageBox.Show("can't Insert there is error :" + ex, "Error");
}
finally
{
conn.Close();
}
}
這裏是SQL
DB端的存儲過程。存儲過程sql數據插入錯誤
use GDK
GO
create PROCEDURE dbo.empInsert
@id as VARCHAR(10,
@name as VARCHAR(10),
@cell as VARCHAR(10),
@address as VARCHAR(20)
AS
BEGIN
INSERT INTO EmployeeRecord(empcode,empname,empcell,empaddress) VALUES(@id, @name, @cell, @address)
END
我無法在數據庫中使用INSERT
。
在這方面請幫助
在應用程序代碼中的參數名稱必須在您所呼叫的數據庫匹配底層存儲過程。 –