SQL语句:
string queryStringRgt = @"SELECT TB_YWDA.ywda_SeqNO as 顺序号, TB_YWDAJ.ywdaj_DirName as 档号, TB_YWDAJ.ywdaj_KeepPeriod as 保管期限, TB_YWDAJ.ywdaj_Year as 年度, "
+ " TB_YWDA.ywda_Responsible as 责任者, TB_YWDA.ywda_Title as 题名, TB_YWDA.ywda_PageNO as 页号, TB_YWDAJ.ywdaj_Type as 档案类别, "
+ " TB_YWDA.ywda_PageSum as 页数, TB_YWDA.ywda_CreatedTime as 成文时间, TB_YWDA.ywda_ID, TB_YWDA.ywdaj_ID FROM TB_YWDA left join TB_YWDAJ on TB_YWDA.ywdaj_ID = TB_YWDAJ.ywdaj_ID where CInt(TB_YWDA.ywdaj_ID) = '" + selectedYwdajID + "'";
数据加载代码:
OleDbCommand SQLQuery = new OleDbCommand();
DataTable data = new DataTable();
this.skinDataGridViewRgt.DataSource = null;
SQLQuery.Connection = null;
OleDbDataAdapter dataAdapter = null;
this.skinDataGridViewRgt.Columns.Clear(); // <-- clear columns
//---------------------------------
SQLQuery.CommandText = sqlQueryString;
SQLQuery.Connection = dataBase;
dataAdapter = new OleDbDataAdapter(SQLQuery);
MessageBox.Show("hah");
dataAdapter.Fill(data); //问题出在这一行
skinDataGridViewRgt.DataSource = data;
之前另一个sql语句时,都没有错误,改了之后就出现问题了,谢谢大神帮忙解决一下。
------解决思路----------------------
不知道是不是不能正常处理NULL,看下ACCESS以下查询有没有结果
SELECT
TB_YWDA.ywda_SeqNO as 顺序号
, TB_YWDAJ.ywdaj_DirName as 档号
, TB_YWDAJ.ywdaj_KeepPeriod as 保管期限
, TB_YWDAJ.ywdaj_Year as 年度
, TB_YWDA.ywda_Responsible as 责任者
, TB_YWDA.ywda_Title as 题名
, TB_YWDA.ywda_PageNO as 页号
, TB_YWDAJ.ywdaj_Type as 档案类别
, TB_YWDA.ywda_PageSum as 页数
, TB_YWDA.ywda_CreatedTime as 成文时间
, TB_YWDA.ywda_ID
, TB_YWDA.ywdaj_ID
FROM TB_YWDA
left join TB_YWDAJ on TB_YWDA.ywdaj_ID = TB_YWDAJ.ywdaj_ID
where CInt(TB_YWDA.ywdaj_ID) = 'selectedYwdajID'
AND TB_YWDAJ.ywdaj_ID IS NULL
------解决思路----------------------
CInt(TB_YWDA.ywdaj_ID) 为什么要加 CInt?这个字段不应该本来就设计为Int类型吗?
如果TB_YWDA.ywdaj_ID有空值,加了 CInt() 就会报“无效的null使用”!