Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running Access application from Task Scheduler 6 27
Problem to error 4 43
Server Error 11 45
Ajax Panel Not Updating When Triggered By Timer 4 36
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 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

20 Experts available now in Live!

Get 1:1 Help Now