private void button1_Click(object sender, EventArgs e)
{
SqlConnection cs = new SqlConnection("Data Source=SALE7\\SALE7;Initial Catalog=YOUTUBE;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand("INSERT INTO tblContacts VALUES (@FIRSTNAME,@LASTNAME)", cs);
da.InsertCommand.Parameters.Add("@FIRSTNAME", SqlDbType.VarChar).Value = textBox1.Text;
da.InsertCommand.Parameters.Add("@LASTNAME", SqlDbType.VarChar).Value = textBox2.Text;
cs.Open();
da.InsertCommand.ExecuteNonQuery(); // Error occurs here
cs.Close();
}
异常详情:
列名或提供的值的数量与表定义不匹配。