SqlCommand cmd1 = new SqlCommand("select * from app where date='" + dateTimePicker2.Value + "'", connection);
// MessageBox.Show(cmd1.CommandText);
SqlDataAdapter da = new SqlDataAdapter(cmd1);
DataTable dt = new DataTable();
da.Fill(dt);
//dataGridView1.DataSource = dt;
connection.Open();
if (dt.)
{
textBox1.Text = dt.Rows[0]["company"].ToString();
textBox2.Text = dt.Rows[0]["place"].ToString();
dateTimePicker1.Text = dt.Rows[0]["date"].ToString();
textBox3.Text = dt.Rows[0]["time"].ToString();
}
else
{
}
connection.Close();
control_logoff();
adminlogin();
}
在我的应用程序中,我想检查数据表是否没有记录,它不应该抛出错误,就像位置0没有行一样。
答案 0 :(得分:2)
怎么样
if(dt.Rows.Count() != 0){}
答案 1 :(得分:0)
if(dt.Rows.Count > 0) should do it.