Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 480
  • Last Modified:

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

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
SweetingA
Asked:
SweetingA
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
What does the data adapter's UpdateCommand text look like?
0
 
SweetingAAuthor Commented:
Don't know - as i told you i am a complete novice, please explain in idots language, thanks
0
 
Bob LearnedCommented:
How was the update query generated?
0
 
SweetingAAuthor Commented:
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
 
SweetingAAuthor Commented:
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now