I am trying to add records to a table of my access database.
When I create the SQL string I get an error. I am not sure what is the problem but I am guessing the path.
This is the SQLstr that creates the error:Code:Private Sub AddRecords(sPath As String) Dim SQLstr As String Dim Command As OleDbCommand Dim icount As Integer Dim di As New DirectoryInfo(sPath) ' Get a reference to each file in that directory. Dim fiArr As FileInfo() = di.GetFiles() ' Display the names of the files. Dim fri As FileInfo Try Dim sName As String Dim sLastAcc As String Dim sType As String Dim Size As String For Each fri In fiArr sType = Path.GetExtension(fri.Name).ToLower() sLastAcc = fri.LastAccessTime Size = FileLen(sPath & fri.Name) sName = UCase(fri.Name) SQLstr = "INSERT INTO Documents ([Document Location],[Document Type],[Last Accessed],[File Size],[Document Name],[OldName]) VALUES '" & sPath & "','" & sType & "','" & sLastAcc & "','" & Size & "','" & sName & "','" & sName & "'" Command = New OleDbCommand(SQLstr, con) icount = Command.ExecuteNonQuery Next fri Catch ex As Exception MessageBox.Show(ex.Message & " - " & ex.Source) End Try End Sub
Code:INSERT INTO Documents ([Document Location],[Document Type],[Last Accessed],[File Size],[Document Name],[OldName]) VALUES 'C:\INFORMATIE OPSLAG\2021\','.pdf','17-4-2021 14:29:02','137992','MY.FILE.IN.DIRECTORY.20210414.PDF','MY.FILE.IN.DIRECTORY.20210414.PDF'




Reply With Quote
