我有这段代码,它总是返回-1。我有三个表(一张图片更具暗示性):
我想看看该行是否已经在 ReservationDetails 表中,如果不是要插入它。
try
{
SqlConnection conn = new SqlConnection...
SqlCommand slct = new SqlCommand("SELECT * FROM ReservationDetails WHERE rID=@rID AND RNumber=@RNumber", conn);
slct.Parameters.AddWithValue("@rID", (int)comboBox1.SelectedValue);
slct.Parameters.AddWithValue("@RNumber", dataGridView1.SelectedRows[0].Cells[0].Value);
int noRows;//counts if we already have the entry in the table
conn.Open();
noRows = slct.ExecuteNonQuery();
conn.Close();
MessageBox.Show("The result of select="+noRows);
if (noRows ==0) //we can insert the new row