我有這樣的代碼,它總是返回-1.I有三個表(圖片更暗示): C# - 受影響的行SELECT查詢編號始終是-1
我想看看是否行已經在ReservationDetails表中,並且不是要插入它。
try
{
SqlConnection conn = new SqlConnection...
SqlCommand slct = new SqlCommand("SELECT * FROM ReservationDetails WHERE [email protected] AND [email protected]", 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
你爲什麼要對'SELECT'語句使用'ExecuteNonQuery'? – 2012-04-07 08:42:00
那我該用什麼? P.S.它不是一個大項目,所以沒有人會插入任何東西:) – NiCU 2012-04-07 08:45:55