Solved

Update SQL table from datagrid after datagrid combobox selection changed (or from button)

Posted on 2014-07-25
5
447 Views
Last Modified: 2014-07-27
I am populating a datagrid with information from an SQL table.
I am replacing one of the table columns with a combobox populated from a column in another SQL table.
All works fine.
After i make a selection in the combobox, i want to press a button and send the updated result back to the SQL table but i keep getting an error "Update unable to find TableMapping['temptbl_Stops'] or DataTable 'temptbl_Stops'." which i find very strange as thats what i load in the first place.

See code example below - any help most welcome.  I am a complete novice so please be patient with me!

 Public Sub LoadDowntimeRecords()
        'Load downtime records
        SQL.RunQuery("SELECT * FROM temptbl_Stops")
        'MsgBox(SQL.recordcount)
        SQL.SQLDA.Fill(SQL.SQLDataSet, "temptbl_Stops")
        DGVDTRecords.DataSource = SQL.SQLDataSet.Tables("temptbl_Stops")
        Dim cbo As New DataGridViewComboBoxColumn()
        DGVDTRecords.Columns.Add(cbo)
        cbo.HeaderText = "DC"
        SQL.RunQuery("SELECT DowntimeCode FROM tbl_DowntimeCodes")
        If SQL.SQLCon.State = ConnectionState.Closed Then SQL.SQLCon.Open()
        Dim SQLDR As SqlDataReader = SQL.SQLCmd.ExecuteReader()
        While SQLDR.Read = True
            cbo.Items.Add(SQLDR.Item("DowntimeCode"))
        End While
        SQL.SQLCon.Close()
    End Sub

    Private Sub cmdStore_Click(sender As System.Object, e As System.EventArgs) Handles cmdStore.Click
        'update downtime codes in temp table for recorded stops
        SQL.RunQuery("SELECT StartDate ,StopDate ,StopTime, DowntimeCode FROM temptbl_Stops")
        If SQL.SQLCon.State = ConnectionState.Closed Then SQL.SQLCon.Open()
        SQLDB = New SqlCommandBuilder(SQL.SQLDA)
        SQL.SQLDA.Update(SQL.SQLDataSet, "temptbl_Stops")
        MessageBox.Show("Information Updated", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
        SQL.SQLCon.Close()
    End Sub
0
Comment
Question by:SweetingA
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40221349
What does the data adapter's UpdateCommand text look like?
0
 

Author Comment

by:SweetingA
ID: 40221566
Don't know - as i told you i am a complete novice, please explain in idots language, thanks
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40222648
How was the update query generated?
0
 

Author Comment

by:SweetingA
ID: 40222731
Hi,

I have fixed the problem a totally different way.
In the combobox selecteditemcommitted event i simply used

SQL.RunQuery("UPDATE temptbl_Stops SET DowntimeCode = '" & dc & "' WHERE ID = " & ID & " ")

and that did all i needed

the other code i was trying to use i got off the net and never fully understood what it was supposed to do
0
 

Author Closing Comment

by:SweetingA
ID: 40223273
HI Bob,

Although the solution was not stated as  a result of my inability to state the question precisely, your hint sent me in the right direction and make me think a little differently to get there in the end so i want to award the points anyway.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 …

790 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