标准表达式中数据类型不匹配?

lj2002aaa188 2016-02-14 10:55:18
提示错误标准表达式中数据类型不匹配。
//连接数据库
string strPath = Application.StartupPath + "\\预报会商意见.mdb";
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + strPath;
OleDbConnection oleCon = new OleDbConnection(ConStr);
oleCon.Open();
string sqlStr;
sqlStr = "select * from table1 where 会商日期>='"+dateTimePicker1.Value.ToString("yyyy-MM-dd")+"' and 会商日期<='"+dateTimePicker2.Value.ToString("yyyy-MM-dd")+"'";
OleDbDataAdapter oleDap = new OleDbDataAdapter(sqlStr, oleCon);
DataSet ds = new DataSet();
oleDap.Fill(ds, "table1");
dataGridView1.DataSource = ds.Tables[0].DefaultView;
oleCon.Dispose();
oleCon.Close();


错误信息(看不明白):
未处理 System.Data.OleDb.OleDbException
Message="标准表达式中数据类型不匹配。"
Source="Microsoft JET Database Engine"
ErrorCode=-2147217913
StackTrace:
在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
在 System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
在 预报输入.Form3.button1_Click(Object sender, EventArgs e) 位置 E:\程序设计\C#工程文件\预报输入\Form3.cs:行号 31
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 预报输入.Program.Main() 位置 E:\程序设计\C#工程文件\预报输入\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
...全文
384 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Justin-Liu 2016-02-15
  • 打赏
  • 举报
回复
看你的SQL语句是什么,有问题
qbilbo 2016-02-15
  • 打赏
  • 举报
回复
sqlStr = "select * from table1 where 会商日期>=#"+dateTimePicker1.Value.ToString("yyyy-MM-dd")+"# and 会商日期<=#"+dateTimePicker2.Value.ToString("yyyy-MM-dd")+"#";
bdmh 2016-02-15
  • 打赏
  • 举报
回复
而且对于access,日期型字段需要加井号,类似 WHERE StrDate > #2011-8-19#
bdmh 2016-02-15
  • 打赏
  • 举报
回复
会商日期 字段是字符型的吗,如果不是,就不要加引号
fhwish 2016-02-14
  • 打赏
  • 举报
回复
tostring里面格式转换不过去?

111,083

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧