Я заполнил таблицу в msaccess с данными с некоторого веб-ресурса. метаданных таблицы в MSAccess и мой код, какисключение oledb Тип данных несоответствие в выражении критериев
Dim Con1 As OleDbConnection = Nothing
Dim LastDateTimeOfRawNews As DateTime = Nothing
Private Function copyLatestNewstoNewsAndTemporary()
Con1 = DB_Manager.getConnection()
Con1.Open()
Dim SQL2 As String = ""
LastDateTimeOfRawNews = "#6/7/2013 4:36:46 PM#"
SQL2 = "insert into TemporaryNews(Title) SELECT Title FROM News where News.news_Date >='" + LastDateTimeOfRawNews + "'"
Dim objCmd2 As OleDbCommand = New OleDbCommand(SQL2, Con1)
objCmd2.ExecuteNonQuery()
Con1.Close()
End Function
метаданные:
NewsId -> AutoNumber
Title -> Text
news_Date Date/Time etc
я получил исключение
exception full detail is as under
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147217913
Message=Data type mismatch in criteria expression.
Source=Microsoft JET Database Engine
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at WBand.frmMain.copyLatestNewstoNewsAndTemporary() in C:\Users\Khanz\Desktop\Latest news\Editing\WBand\Form1.vb:line 679
at WBand.frmMain.Button3_Click(Object sender, EventArgs e) in C:\Users\Khanz\Desktop\Latest news\Editing\WBand\Form1.vb:line 918
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WBand.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Также пожалуйста скажите { "несоответствие типов данных в выражении критериев."} мне есть разница между типом datetime типа msaccess и типом datetime vb.net.
Вы присваивающих значение строки 'LastDateTimeOfRawNews' и использовать его в качестве строки в переменную, которая содержит SQL-запрос. Можете ли вы попытаться определить его как «Dim LastDateTimeOfRawNews As String» в вашем коде? –
Я получаю дату и время от функции, как указано ниже. , , в то время как жестко закодированное значение предназначено только для тестирования и создает одно и то же исключение –
Dim QueryOFLastRecordOFRawNews As String = "SELECT TOP 1 news_Date FROM News ORDER BY NewsId DESC" 'Dim QueryOFLastRecordOFRawNews As String = "SELECT news_Date FROM News, где news_Date = # 6/7/2013 11:36:13 AM #» Dim conn2 Как OleDbConnection = Nothing Dim ЦМД Как OleDbCommand Private Function GetDateTimeOfLastNewsInRawNews (ByRef QueryOFLastRecordOFRawNews As String) –