Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Syntax error in INSERT INTO statement.

Author  Topic 

roxcy
Yak Posting Veteran

58 Posts

Posted - 2007-07-11 : 01:33:24
Hi, I am Trying to insert values in Access DataBase,But getting a syntax error.Following is my code.
         
Dim ConnString As String
Dim i As Integer
Dim str1 As String = "C:\AccessData\Temp.mdb"
Dim StrSql As String
Dim _command As OleDbCommand
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & str1 & ";"
Dim _connection As New OleDbConnection(ConnString)
_connection.Open()
For i = 0 To dtCSV.Rows.Count - 1
StrSql = "Insert into [JOBPART] (code,claimid,sectioncode,defactcode,repaircode)Values('" & dtCSV.Rows(i).Item(0) & "','" & dtCSV.Rows(i).Item(1) & "','" & dtCSV.Rows(i).Item(2) & "','" & dtCSV.Rows(i).Item(3) & "','" dtCSV.Rows(i).Item(4) & "')"
_command = New OleDbCommand(StrSql, _connection)
_command.Connection = _connection
_command.ExecuteNonQuery()
Next
_connection.Close()


Any help would be appreciated.
Thanks..

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-11 : 02:40:46
If you also put in a

debug.print strsql

what do the string contain? It is a valid syntax?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -