I want to UPDATE query instead INSERT INTO using this code help me thanks.

Dim cmd As New OleDbCommand("INSERT INTO tblPurchase_Order ([Order_Id],[Supplier_Id],[Address],[Project_Id],[dtpDate],[Material_Id],[Material_Name],[Unit],[Quantity],[Unit_Price],[Amount]) VALUES (@Order_Id,@Supplier_Id,@Address,@Project_Id,@dtpDate,@Material_Id,@Material_Name,@Unit,@Quantity,@Unit_Price,@Amount)", conn)
                cmd.Connection = conn
                cmd.CommandType = CommandType.Text
                cmd.Parameters.AddWithValue("@Order_Id", lstItems.Items(i).SubItems(0).Text)
                cmd.Parameters.AddWithValue("@Supplier_Id", lstItems.Items(i).SubItems(1).Text)
                cmd.Parameters.AddWithValue("@Address", lstItems.Items(i).SubItems(2).Text)
                cmd.Parameters.AddWithValue("@Project_Id", lstItems.Items(i).SubItems(3).Text)
                cmd.Parameters.AddWithValue("@dtpDate", lstItems.Items(i).SubItems(4).Text)
                cmd.Parameters.AddWithValue("@Material_Id", lstItems.Items(i).SubItems(5).Text)
                cmd.Parameters.AddWithValue("@Material_Name", lstItems.Items(i).SubItems(6).Text)
                cmd.Parameters.AddWithValue("@Unit", lstItems.Items(i).SubItems(7).Text)
                cmd.Parameters.AddWithValue("@Quantity", lstItems.Items(i).SubItems(8).Text)
                cmd.Parameters.AddWithValue("@Unit_Price", lstItems.Items(i).SubItems(9).Text)
                cmd.Parameters.AddWithValue("@Amount", lstItems.Items(i).SubItems(10).Text)

All you need to do is to reformat the query into an UPDATE query.
Like so:

Dim cmd As New OleDbCommand("UPDATE tblPurchase_Order SET " _
"[Supplier_Id] = @Supplier_Id, [Address] = @Address, [Project_Id] = @Project_Id, " _
"[dtpDate] = @dtpDate, [Material_Id] = @Material_Id, [Material_Name] = @Material_Name, _
"[Unit] = @Unit, [Quantity] = @Quantity, [Unit_Price] = @Unit_Price, " _
"[Amount] = @Amount WHERE [Order_Id] = @Order_Id")

cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Order_Id", lstItems.Items(i).SubItems(0).Text)
cmd.Parameters.AddWithValue("@Supplier_Id", lstItems.Items(i).SubItems(1).Text)
cmd.Parameters.AddWithValue("@Address", lstItems.Items(i).SubItems(2).Text)
cmd.Parameters.AddWithValue("@Project_Id", lstItems.Items(i).SubItems(3).Text)
cmd.Parameters.AddWithValue("@dtpDate", lstItems.Items(i).SubItems(4).Text)
cmd.Parameters.AddWithValue("@Material_Id", lstItems.Items(i).SubItems(5).Text)
cmd.Parameters.AddWithValue("@Material_Name", lstItems.Items(i).SubItems(6).Text)
cmd.Parameters.AddWithValue("@Unit", lstItems.Items(i).SubItems(7).Text)
cmd.Parameters.AddWithValue("@Quantity", lstItems.Items(i).SubItems(8).Text)
cmd.Parameters.AddWithValue("@Unit_Price", lstItems.Items(i).SubItems(9).Text)
cmd.Parameters.AddWithValue("@Amount", lstItems.Items(i).SubItems(10).Text)

i got an error >>Extra ) in query expression '[Material_Id]=@Material_Id)'.
Sir, my problem is i want to update all item in my listview

here

Dim ii As Integer
            For ii = 0 To lstItems.Items.Count - 1
                Dim cmd1 As New OleDbCommand("UPDATE tblMaterials SET [Material_Name]=@Material_Name, [Quantity]=@Quantity WHERE [Material_Id]=@Material_Id)", conn)
                cmd1.Connection = conn
                cmd1.CommandType = CommandType.Text
                cmd1.Parameters.AddWithValue("@Material_Id", lstInventory.Items(ii).SubItems(0).Text)
                cmd1.Parameters.AddWithValue("@Material_Name", lstInventory.Items(ii).SubItems(1).Text)
                cmd1.Parameters.AddWithValue("@Quantity", lstInventory.Items(ii).SubItems(2).Text)

                conn.Open()
                cmd1.ExecuteNonQuery()
                conn.Close()
            Next ii
            lstItems.View = View.Details

Extra ) in query expression '[Material_Id]=@Material_Id)'. :(

Thanks you Oxiegen,

* Thank you Oxiegen finally It works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.