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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:35:07+00:00 2026-06-10T06:35:07+00:00

I am trying to insert multiple rows in a listitems to a database using

  • 0

I am trying to insert multiple rows in a listitems to a database using parameters.
But it won’t give me any errors, and also won’t insert any data in the table.
does anyone have any ideas on this one?

  strSQL = "insert into tbltrans2 (transid,itemcode,itemname,qty,price,[total],btw) values ( ?,?,?,?,?,?,?)"
    Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\POS.mdb"), _
          cmd As New OleDbCommand(strSQL, cn)

        cmd.Parameters.Add("?", OleDbType.VarChar).Value = 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
        Next ls

    End Using

Hey steve, When I try that, it gives me ‘syntax error in update statement’ erro. Here is my code:

 Try
        strSQL = "UPDATE set instock = ? where itemcode= ?"
        Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\POS.mdb"), _
               cmd As New OleDbCommand(strSQL, cn)
            cn.Open()
            For Each ls As ListViewItem In ListItems.Items
                cmd.Parameters.Add("?", OleDbType.Integer).Value = 100
                cmd.Parameters.Add("?", OleDbType.VarChar).Value = ls.Tag
                cmd.ExecuteNonQuery()
            Next ls
            cn.Close()
        End Using
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

Now, I still need help with decreasing the stock. Here is the code that I use, but it isn’t working.

  strSQL = "UPDATE tblitem set instock ='instock'- ? where itemcode = ?"
            Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\POS.mdb"), _
                   cmd As New OleDbCommand(strSQL, cn)
                cn.Open()
                For Each ls As ListViewItem In SalesListItems.Items
                    If Not (ls.SubItems(1).Tag(0) = "n") Then
                        cmd.Parameters.Add("?", OleDbType.Integer).Value = ls.SubItems(1).Text
                        cmd.Parameters.Add("?", OleDbType.VarChar, 10).Value = ls.Tag
                        cmd.ExecuteNonQuery()
                    End If
                Next ls
                cn.Close()
            End Using
  • 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-10T06:35:09+00:00Added an answer on June 10, 2026 at 6:35 am

    You are missing the execute part

    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 
    

    Also, are you certain on the input values coming from the subitems? If there isn’t a control on their effective numeric value when you add them to the ListView, then the loop could fail with an exception when you try to convert the supposed numeric value with Parse.

    EDIT: This instead for an update

    strSQL = "UPDATE tblitem set instock = ? where itemcode= ?"  
    Using cn As New OleDbConnection("......")   
        cmd As New OleDbCommand(strSQL, cn)  
        cmd.Parameters.Add("?", OleDbType.Integer).Value = 100
        cmd.Parameters.Add("?", OleDbType.VarChar).Value = yourItemCodeValue    
        cmd.ExecuteNonQuery()
    End Using    
    

    Keep in mind that I suppose instock is a integer data type and itemcode a varchar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert huge multiple rows in a single transaction. But the
I'm trying to insert multiple rows using SqlCommand from C# to SQL Server. I'm
I'm trying to insert multiple rows using transaction-bind through PHP PDO. Below is my
I'm trying to insert multiple rows but I continue getting an sqlerror and cannot
I am trying to insert multiple rows into MySQL DB using PHP and HTML
I'm trying to insert multiple rows into MySql with only one INSERT INTO statement
I am completely new in MySQL and trying to insert multiple rows in MySQL
I'm trying to insert an HTML blob into our sql-server2005 database. I've been using
I an trying to INSERT multiple rows into an SQL, Oracle table though SQL
I am trying to get multiple rows to insert into a mysql table from

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.