Solved

Save Changes to Datagridview

Posted on 2009-05-18
6
818 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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