Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:51:23+00:00 2026-06-05T14:51:23+00:00

I am using VB .Net to loop through a regex Match and generate a

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:51:25+00:00Added an answer on June 5, 2026 at 2:51 pm

    You need to split your insert statement ,you have to use the “insert into…” every time that you want to insert something in the Address but also if you want to to execute it just once in VB you need to separate each statement with the semicolon (;), it should work

    You need to do something like this.

    Insert Into Agencies (Address) Values
     (" 1330 W Indian School Rd, ");
     Insert Into Agencies (Address) Values
     (" 3323 E Baseline Rd, ");
     Insert Into Agencies (Address) Values
     (" 207 N Gilbert Rd, ");
     Insert Into Agencies (Address) Values
     (" 3160 S. Gilbert Rd., Ste. 4, ");
    

    Edit

    your while should be

    While MatchObj.Success
    sql = " Insert Into Agencies (Address) Values"
    
        sql = sql & "(""" & MatchObj.Groups(1).Value & """); "
        MatchObj = MatchObj.NextMatch()
    End While
    

    Although I strongly recommend to insert each one in separate statements and in a transaction, but it depends to you.


    Edit 2

    You can’t insert multiple records at the same time in MS- Access you must do it insert per insert like…

    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()
            conn.Close()
    End Sub
    
     While MatchObj.Success
        sql = " Insert Into Agencies (Address) Values"
    
            sql = sql & "(""" & MatchObj.Groups(1).Value & """); "
            executeSQL(sql )
            MatchObj = MatchObj.NextMatch()
        End While
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to loop through multiple (dynamic) radio button groups using jQuery, and if
Using C# (or VB.NET) which loop (for loop or do/while loop) should be used
Using .NET and the Word Interop I am programmatically creating a new Word doc
I have a string like the following in C#. I need to loop through
I have referred to the following question at: Using foreach loop to iterate through
I have a long string, and I'd like to loop through it and pull
Using VB.net (.net 2.0) I have a string in this format: record1_field1,record1_field2,record2_field3,record2_field1,record2_field2, etc... I
I know how to loop through a GridView and extract each row using the
I am using ASP.NET Web Forms/C# . I am having this function in my
I'm using ASP.NET MVC 3, and just ran into a 'gotcha' using the DropDownListFor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.