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 8422359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:25:22+00:00 2026-06-10T03:25:22+00:00

I was trying to insert items in a listview in a database. If I

  • 0

I was trying to insert items in a listview in a database. If I try to insert every records seperately, it takes long if there are more records (even more than 5).
Im currently using this code:

 For Each ls As ListViewItem In ListItems.Items
      strSQL = String.Format("insert into tbltrans (transid,itemcode,itemname,qty,price,[total],btw) values ('{0}','{1}','{2}',{3},{4},'{5}','{6}')", CStr(txtTransId.Text), CStr(ls.Tag), ls.SubItems(0).Text, CDbl(ls.SubItems(1).Text), CDbl(ls.SubItems(2).Text), CDbl(ls.SubItems(3).Text), ((ls.SubItems(5).Text)))
                objDal.ExecuteQuery(strSQL)
Next

So, what I want to do is execute all of the items in one sql query.
I tried this, but didn’t work:

 strSQL = "insert into tbltrans (transid,itemcode,itemname,qty,price,[total],btw) values  "
 For Each ls As ListViewItem In ListItems.Items
                    strSQL += tring.Format("('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", CStr(txtTransId.Text), CStr(ls.Tag), ls.SubItems(0).Text, CDbl(ls.SubItems(1).Text), CDbl(ls.SubItems(2).Text), CDbl(ls.SubItems(3).Text), ((ls.SubItems(5).Text)))

                Next
objdal.executequery(strSQL)

It says that it’s missing semicolon(;) at the end of the statement, I tried adding them in the records and also (strsql & “;”), then it gives syntax error.

can anyone help please?

  • 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-10T03:25:23+00:00Added an answer on June 10, 2026 at 3:25 am

    You can do a little better by re-using the same command/connection object and same (not re-constructed) sql string like this (I had to guess at column types and lengths):

    strSQL = "insert into tbltrans (transid,itemcode,itemname,qty,price,[total],btw) values ( ?,?,?,?,?,?,?)"
    
    Using cn As New OleDbConnection("Connection string here"), _
          cmd As New OleDbCommand(strSQL, cn)
    
        cmd.Parameters.Add("?", OleDbType.Integer).Value = Integer.Parse(txtTransId.Text)
        cmd.Parameters.Add("?", OleDbType.VarChar, 10)
        cmd.Parameters.Add("?", OleDbType.VarChar, 50)
        cmd.Parameters.Add("?", OleDbType.Integer)
        cmd.Parameters.Add("?", OleDbType.Decimal)
        cmd.Parameters.Add("?", OleDbType.Decimal)
        cmd.Parameters.Add("?", OleDbType.VarChar, 50)
    
        cn.Open()
        For Each ls As ListViewItem In ListItems.Items
            cmd.Parameters(1).Value = ls.Tag
            cmd.Parameters(2).Value = ls.SubItems(0).Text
            cmd.Parameters(3).Value = Integer.Parse(ls.SubItems(1).Text)
            cmd.Parameters(4).Value = Decimal.Parse(ls.SubItems(2).Text)
            cmd.Parameters(5).Value = Decimal.Parse(ls.SubItems(3).Text)
            cmd.Parameters(6).Value = ls.SubItems(5).Text
            cmd.ExecuteNonQuery()
        Next ls
    
    End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert several newly created items to the database. I have a
I'm trying to insert new records into SQLite database from Python code. con =
I've never used the ListView control before and am trying to programmatically insert items
I am trying to use AsyncQueryHandler to insert items in my Database in a
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
I'm trying to insert the current date/time to the database as the last time
When I click a button, I am trying to insert a new listview item.
I'm trying to insert items in a listbox, but I want to color the
I am trying to insert data into a PostgreSQL database table using Python. I
im trying to create a ListView filled with items fetched from an API, and

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.