新手在这里,我在将数据集保存到数据库文件时遇到问题。我找不到INSERT INTO语句来纠正,还是真的没有包含在代码中?我该如何解决这个问题。谢谢大家!
Private Sub btnRead_Click(sender As System.Object, e As System.EventArgs) -
Handles btnRead.Click
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM DTR"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "DTR")
Dim strFileNameAndPath As String = txtFileLoc.Text
'codes assigning data's into arrays for use by database
'Create rows on database
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim newrow As DataRow = ds.Tables("DTR").NewRow
newrow("EmpNo") = empNo
newrow("EmpName") = empName
newrow("WorkDate") = workDate
newrow("Day") = workDay
newrow("TimeIn1") = in1
newrow("TimeOut1") = out1
newrow("TimeIn2") = in2
newrow("TimeOut2") = out2
newrow("NextDay") = nextDay
newrow("HoursWork") = hrsWork
ds.Tables("DTR").Rows.Add(newrow)
Me.Validate()
da.Update(ds.Tables("DTR")) 'ERROR APPEARS HERE
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End While
DataGridView1.AutoGenerateColumns = False
DataGridView1.ColumnCount = 4
DataGridView1.Columns(0).Name = "Date"
DataGridView1.Columns(0).HeaderText = "Date"
DataGridView1.Columns(0).DataPropertyName = "WorkDate"
DataGridView1.Columns(1).Name = "Day"
DataGridView1.Columns(1).HeaderText = "Day"
DataGridView1.Columns(1).DataPropertyName = "Day"
DataGridView1.Columns(2).Name = "Time In"
DataGridView1.Columns(2).HeaderText = "Time IN"
DataGridView1.Columns(2).DataPropertyName = "TimeIn1"
DataGridView1.Columns(3).Name = "Time Out"
DataGridView1.Columns(3).HeaderText = "Time OUT"
DataGridView1.Columns(3).DataPropertyName = "TimeOut2"
DataGridView1.DataSource = ds.Tables("DTR")
End Using
con.Close()
MsgBox("Connection is closed")
End Sub
以下是错误的堆栈跟踪...
System.Data.OleDb.OleDbException was ErrorCode=-2147217900
Message=Syntax error in INSERT INTO statement.
Source=Microsoft Office Access Database Engine
StackTrace:
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at WindowsApplication17.Form1.btnRead_Click(Object sender, EventArgs e) in c:\users\arlo\documents\visual studio 2010\Projects\WindowsApplication17\Form1.vb:line 125
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(IntPtr 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 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication17.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: