c#问题:关键字 'where' 附近有语法错误。请帮帮忙,无限感激
privatevoidbutton1_Click(objectsender,EventArgse){conn=newSqlConnection(str);if(textB...
private void button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection(str);
if (textBox1.Text == "" && dateTimePicker1.Text == "")
str1 = "select *from 卫生检查信息表";
else
{
if (textBox1.Text != "")
str1 = str1 + " where 宿舍号='" + textBox1.Text + "'";
if (dateTimePicker1.Text != "")
str1 = str1 + "where 检查日期='" + dateTimePicker1.Text + "'";
}
da = new SqlDataAdapter(str1, conn);
DataSet ds = new DataSet();
ds.Clear();
da.Fill(ds, "卫生检查信息表");
dataGridView1.DataSource = ds.Tables["卫生检查信息表"].DefaultView;
str1 = "select * from 卫生检查信息表";
conn.Close();
} 展开
{
conn = new SqlConnection(str);
if (textBox1.Text == "" && dateTimePicker1.Text == "")
str1 = "select *from 卫生检查信息表";
else
{
if (textBox1.Text != "")
str1 = str1 + " where 宿舍号='" + textBox1.Text + "'";
if (dateTimePicker1.Text != "")
str1 = str1 + "where 检查日期='" + dateTimePicker1.Text + "'";
}
da = new SqlDataAdapter(str1, conn);
DataSet ds = new DataSet();
ds.Clear();
da.Fill(ds, "卫生检查信息表");
dataGridView1.DataSource = ds.Tables["卫生检查信息表"].DefaultView;
str1 = "select * from 卫生检查信息表";
conn.Close();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询