Solved

Save Changes to Datagridview

Posted on 2009-05-18
6
810 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

757 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

19 Experts available now in Live!

Get 1:1 Help Now