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();
}
}
Here is Stored procedure on SQL DB side.
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
I am unable to INSERT in DB.
Kindly help in this regard