sda.Fill(ds) 有错误
privatevoidbutton1_Click(objectsender,EventArgse){stringsql="selectUIDas'员工编号',UNamea...
private void button1_Click(object sender, EventArgs e)
{
string sql = "select UID as '员工编号',UName as '员工姓名',URemoveDate as '调动时间',UOldDep as '原部门',UNewDep as '现部门',UOldJob as '原职务',UNewJob as '现职务',UOldPay as '原工资',UNewPay as '工资调整',UPayExplain as '调动说明' from tb_redeploy";
if (date1.Text.Trim() != "" && date2.Text.Trim() != "")
{
DateTime dt1 = Convert.ToDateTime(date1.Text);
DateTime dt2 = Convert.ToDateTime(date2.Text);
sql = sql + " where URemoveDate between " + "#" + dt1 + "#" + " and " + "#" + dt2 + "#";
}
SqlConnection conn = DBConnection.MyConnection();
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
ds.Dispose();
} 展开
{
string sql = "select UID as '员工编号',UName as '员工姓名',URemoveDate as '调动时间',UOldDep as '原部门',UNewDep as '现部门',UOldJob as '原职务',UNewJob as '现职务',UOldPay as '原工资',UNewPay as '工资调整',UPayExplain as '调动说明' from tb_redeploy";
if (date1.Text.Trim() != "" && date2.Text.Trim() != "")
{
DateTime dt1 = Convert.ToDateTime(date1.Text);
DateTime dt2 = Convert.ToDateTime(date2.Text);
sql = sql + " where URemoveDate between " + "#" + dt1 + "#" + " and " + "#" + dt2 + "#";
}
SqlConnection conn = DBConnection.MyConnection();
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
ds.Dispose();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询