Solved

Save Changes to Datagridview

Posted on 2009-05-18
6
820 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

763 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