wcams 2016-07-01 02:00 采纳率: 0%
浏览 1240

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条回答

  • 岁月落寞忆流年 2016-07-01 04:21
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?