try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Storage (Serial,Name) VALUES (@Serial,@Name)", con))
{
connection.Open();
cmd.Parameters.Clear();
cmd.Parameters.Add("@Serial", txtSerial.Text);
cmd.Parameters.Add("@Name", txtName.Text);
int res=cmd.ExecuteNonQuery();
if (res > 0)
{
MessageBox.Show("Done");
}
else
{
MessageBox.Show("Error");
}
connection.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
please use sql quary after connection variable name like this
using (SqlCommand cmd = new SqlCommand("INSERT INTO Storage (Serial,Name) VALUES (@Serial,@Name)", ******** ))