新手请教:SQL查询到的数据放在datagridview中,但是是空的
无论我怎么查询,查出来的都是空的,逐步调试发现dt也是空的,请问该如何改正? private void button2_Click(object sender, EventArgs e)//点击按钮查询
{
string shijian = events.Text.Trim();//读取文本框的值
string con_str = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=D:\C#测试\LOGIN\LOGIN\BIN\DEBUG\WORKEVENTS.MDF;Integrated Security=True";
string query =String.Format( "select events,recorddate,finishdate,department,supplier,price from workevensts where events={0}", @" ' " + shijian + @"% ' ");
SqlConnection conn = new SqlConnection(con_str);
SqlCommand cmd = new SqlCommand(query,conn);
= query;
SqlDataAdapter ada = new SqlDataAdapter();//数据适配器,访问数据用的
ada.SelectCommand = cmd;
DataTable dt = new DataTable();
ada.Fill(dt);
dataGridView1.DataSource = dt;
}
}
[此贴子已经被作者于2018-9-25 20:36编辑过]