Solved

Save Changes to Datagridview

Posted on 2009-05-18
6
814 Views
Last Modified: 2013-11-08
I am trying to save any changes to a datagridview control to a Microsoft Access database.  I am using the code show below to populate and set the update commands for the datatable.

Dim sSQL As String = "SELECT RecordNumber, LineNum, RecID, Pcs, Wgt FROM tblItems WHERE RecID = '" & sCrit & "' ORDER BY LineNum"

            Dim cn As New OleDbConnection(Global_Values.System_Database)
            daLineItems = New OleDbDataAdapter(sSQL, cn)
            dsLineItems = New DataSet
            dtLineItems = New DataTable

            If cn.State = ConnectionState.Closed Then
                cn.Open()
            End If

            'Insert Command
            Dim cmdInsert As New OleDbCommand("INSERT INTO tblItems (LineNum, RecID, Pcs, Wgt) VALUES (@LineNum, @RecID, @Pcs, @Wgt)", cn)
            daLineItems.InsertCommand = cmdInsert

            'Update Command
            Dim cmdUpdate As New OleDbCommand("UPDATE tblItems SET Line_Num = @LineNum, RecID = @RecID, Pcs = @Pcs, Wgt = @Wgt WHERE RecordNumber = @RecordNumber", cn)
            daItems.UpdateCommand = cmdUpdate

            daItems.Fill(dtLineItems)

            If dtItems.Rows.Count < 1 Then
                dtItems.Rows.Add()
            End If

            Me.DataGridView1.DataSource = dtItems
         

In the on-click event of a button i am using the following in an attempt save the changes back to the database:

          daItems.Update(dtItems)

When i click the save button I get the following error: No value given for one or more required parameters.

What am i doing wrong?

0
Comment
Question by:Mike_Stevens
  • 3
  • 2
6 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24415414
0
 

Author Comment

by:Mike_Stevens
ID: 24415744
Tried that route and I concurrency issues
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24416033
Can you show what have you tried ?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Mike_Stevens
ID: 24422213
I resolved the problem....need to define the parameters for the insert and update commands
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24422260
I looked to that but you didn't needed if you use in other way.
It's working and that is the most important :)
0
 
LVL 3

Expert Comment

by:fordraiders
ID: 33043725
mike stevens, could you post the solution, that you used...having same problem..
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now