这是我在数据库表中显示/搜索记录的代码。如何验证 roecord 是否存在?它正在通过成员的 ID 进行搜索。如果记录不存在,我应该如何显示消息?
string connectionstring = "Server=Momal-PC\\MOMAL;Database=Project;Trusted_Connection=True;";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionstring;
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("Select * from Members where Number = '" + SearchID.Text + "'", conn);
DataTable dtStock = new DataTable();
sda.Fill(dtStock);
dataGridView1.DataSource = dtStock;
conn.Close();
最佳答案
if( 0 == dtStock.Rows.Count ) // does not exist
关于c# - 如何检查行是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16097636/