C#渣新求助dataAdapter问题

写了下面这个方法调用了两次,第一次是在FormLoad事件里,成功运行
第二次在按钮事件中未成功,DataGridView没填充数据,也没报错
SQL语句在数据库中运行也没问题

public static void FillMainDgv(string str,DataGridView dgv)
{
try
{
dgv.Rows.Clear();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(str, DBHelper.connection);
DataSet dataSet = new DataSet("ds");
dataAdapter.Fill(dataSet, "MainTable");
int i = 1;
foreach (DataRow row in dataSet.Tables["MainTable"].Rows)
{
int index = dgv.Rows.Add();
dgv.Rows[index].Cells["Column1"].Value = Convert.ToString(i);
dgv.Rows[index].Cells["id"].Value = row["id"];
dgv.Rows[index].Cells["date"].Value = row["dt"];
dgv.Rows[index].Cells["type"].Value = row["type"];
dgv.Rows[index].Cells["body"].Value = row["body"];
dgv.Rows[index].Cells["money"].Value = row["m"];
dgv.Rows[index].Cells["event1"].Value = row["event"];
dgv.Rows[index].Cells["remark"].Value = row["remark"];
dgv.Rows[index].Cells["time"].Value = row["t"];
i++;
}
dgv.ClearSelection();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
FormLoad的SQL语句
SELECT id, Format([date], 'yyyy/mm/dd') AS dt, type, body, format([money],'0.00') as m, event, remark, Format([time],'yyyy/mm/dd hh:nn:ss') AS t FROM MainTable WHERE DateDiff('d', [date], #2016/06/01#) <=0 AND DateDiff('d', [date], #2016/06/30#) >=0 ORDER BY [date] DESC

Button的SQL语句
SELECT id, Format([date], 'yyyy/mm/dd') AS dt, type, body, format([money],'0.00') as m, event, remark, Format([time],'yyyy/mm/dd hh:nn:ss') AS t FROM MainTable WHERE DateDiff('d', [date], #2016/06/01#) <=0 AND DateDiff('d', [date], #2016/06/30#) >=0 type='支出' AND [event] LIKE '**' OR [remark] LIKE '**' ORDER BY [date] DESC

以上语句在数据库中测试均有结果,请大家帮我看看问题出在什么地方了,谢谢了

1个回答

type='支出' AND [event] LIKE '**' OR [remark] LIKE '**' ORDER BY [date] DESC 前面加上and

wcams
wcams 这上面的代码是手打的,那头是自动生成的,这边打错了,那边没缺
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问