Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA code for SubFolders 11 49
Excel Web Add-in Where is Visual Basic used 9 81
Import a excel sheet in a grid 2 45
Get average for unknown number of cells per degree.. 3 38
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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