对数据库中bit型的State类型‘1’or‘0’的判断,显示出来时候就是是否了
1 //联表查询,根据user表中id查请假表中的数据 2 public DataTable selectLeaveMessage(string chineseWord) 3 { 4 string sql = string.Format("SELECT leaveMessage.UserId, leaveMessage.TrueName, leaveMessage.LeaveTime, leaveMessage.LeaveType,leaveMessage.AppDays, leaveMessage.AddTime ,leaveMessage.State,(case leaveMessage.State when 1 then '是' else '否' end )as Stateaa FROM leaveMessage INNER JOIN demoUsers ON leaveMessage.UserId = demoUsers.UserId WHERE (demoUsers.ChineseWord like @chineseWord )"); 5 DataConn conn = new DataConn(conStr); 6 ArrayList paramlist = new ArrayList(); 7 paramlist.Add(conn.CreateParameter("@chineseWord", "%" + chineseWord + "%", DbType.String, 50)); 8 IDataParameter[] param = (IDataParameter[])paramlist.ToArray(typeof(IDataParameter)); 9 return conn.testDataTable(sql, param); 10 }
多了(case leaveMessage.State when 1 then '是' else '否' end )as Stateaa
红体为新建绑定值在dGV控件中,还可以联想到以后数据库中非空值与空值的处理,可以默认一个初始事件,相当于空值了,这样就避免notnull的冲突,casewhen的判断
.............................................................................数据的读取.............................................................
如果数据是全齐的,要从dataGridView中点击读取到from上,那么可以选择直接读取,或者是获取ID再从数据中读取.
从datagridview控件,点击显示数据
this.label16.Text = dGV1.Rows[e.RowIndex].Cells["LeaveTime"].Value.ToString();
当前的行 要显示的列