I am working on my simple task in c# with service based database. I have a service-based database where I have table staff
with columns id, name and password. I am trying to insert new record into that table, with C# code, but it's not inserting, just telling me "No Record ADDED" even there is no error.
My code is:
private void button5_Click(object sender, EventArgs e)
{
try
{
connetionString = Properties.Settings.Default.testdbConnectionString;
cnn = new SqlConnection(connetionString);
cnn.Open();
SqlCommand command6;
string sql6 = null;
sql6 = "insert into staff (name,pwd,id) values(@n,@p,@fid)";
command6 = new SqlCommand(sql6, cnn);
command6.Parameters.AddWithValue("@n", "jhon");
command6.Parameters.AddWithValue("@p", "test");
command6.Parameters.AddWithValue("@fid", 1);
int result = command6.ExecuteNonQuery();
if (result == 0)
{
MessageBox.Show("Record ADDED");
}
else
{
MessageBox.Show("No Record ADDED");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
If you need more detail you my ask but please correct my mistake. Thanks