sql = "select plandate as 日期,number as 数量,num1 as 开始编号,pipeline as 流水编号,dayornight as 白晚班1,AorS as 层区名称,description as 说明 from gq_sec where factory='" + f.current_factory + "'and gq_pri_id=" + id + " and diff=0 order by 日期 desc";
MySqlDataAdapter comm = new MySqlDataAdapter(sql, conn);
DataTable ds = new DataTable();
comm.Fill(ds);
ds.Columns.Add(new DataColumn() {
ColumnName = "白晚班", DataType = typeof(String) });
ds.Columns["白晚班"].SetOrdinal(5);//由于dayornight数据类型为int,当该列在有数据的情况下转不了string,新增一列,原来一列隐藏
for (int i = 0; i < ds.Rows.Count; i++)
{
if (ds.Rows[i]["白晚班1"].ToString() == "1") ds.Rows[i]["白晚班"] = "白班";
else if (ds.Rows[i]["白晚班1"].ToString() == "2") ds.Rows[i]["白晚班"] = "晚班";
}
dataGridView1.DataSource = ds;
dataGridView1.Columns["白晚班1"].Visible = false;
还没有评论,来说两句吧...