Solved

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

Posted on 2014-07-25
5
432 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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