I am using VB .Net to loop through a regex Match and generate a sql statement. I'm creating the sql like this
sql = "Insert Into Agencies (Address) Values"
While MatchObj.Success
sql = sql & "(""" & MatchObj.Groups(1).Value & """), "
MatchObj = MatchObj.NextMatch()
End While
sql = sql.Substring(0, Len(sql) - 2) & ";"
so when I print sql to the immediate window after creating it, I get this:
Insert Into Agencies (Address) Values(" 1330 W Indian School Rd, "), (" 3323 E Baseline Rd, "), (" 207 N Gilbert Rd, "), (" 3160 S. Gilbert Rd., Ste. 4, ");
I then create a OleDbCommand using the sql statement. I can connect up to the DB but when I run the .ExecuteNonQuery() I get this error: "Missing semicolon (;) at end of SQL statement"
My goal is to use a single INSERT to put all these values into the DB column "Address".
Any help is much appreciated.
Edit: Here is the sub I'm using to open and execute
Public Sub executeSQL(ByVal sql As String)
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Local Projects\AgenciesAZ.mdb'"
Dim conn As OleDbConnection = New OleDbConnection(connString)
Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
conn.Open()
cmd.ExecuteNonQuery() 'error hits here
conn.Close()
End Sub