Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using dataset w/ tableadapter - no updates are occuring on recordset

Status
Not open for further replies.

Maven4Champ

Technical User
Jun 16, 2004
154
Posting code below. Working in our Dev environment on one single table

table: ResponsibilityMaster
ID (pk)
ResponsibilityName
ResponsibilityDesc
LDTSyntax

My goal and intent is to display a drop-down of ResponsibilityName and on change of ResponsibilityName, load the LDTSyntax in the textarea below. The user then hits "Edit Syntax" (Button3) which sets the textarea (TextBox1) to Enabled = True to allow for editing. The user then makes their changes manually or pasts from clipboard (Button2). They would then hit the "Commit Changes" button (Button4) which would complete the edit and update the SQL Server table with the changes they have made.

Here is the problem: Everything works in the application except the most crucial piece (of course) - it's when the user hits the Commit Changes button, the record updates visually in the form but when closing out of the form and going back in OR by querying the db, nothing actually changed. So from there, it leads me to believe I am still only updating the dataset in my form and not actually truly passing those changes to the db.

Code is below:

Code:
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Data.SqlClient

Public Class LDTUpdate


    Private Sub LDTUpdate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'TechWebsiteDataSet.ResponsibilityMaster' table. You can move, or remove it, as needed.
        Me.ResponsibilityMasterTableAdapter.Fill(Me.TechWebsiteDataSet.ResponsibilityMaster)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FrmLDT.Show()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim pasteResponse As Integer
        pasteResponse = MsgBox("Are you sure you want to paste from the clipboard? This cannot be undone.", MsgBoxStyle.YesNo, "LDT Update Confirmation")
        If pasteResponse = vbYes And Me.TextBox1.Enabled = True Then
            Me.TextBox1.Text = Clipboard.GetText()
        ElseIf pasteResponse = vbYes And Me.TextBox1.Enabled = False Then
            MsgBox("You cannot paste text into the text area when disabled. Please choose Edit LDT Syntax before pasting.", MsgBoxStyle.OkOnly, "Past Clipboard Error")
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.TextBox1.Enabled = True
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Me.TextBox1.Enabled = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'Dim tmpSyntax As String = TextBox1.Text
        Dim rowID As Integer = CInt(TextBox2.Text)
        Dim LDTRow() As Data.DataRow = TechWebsiteDataSet.Tables("ResponsibilityMaster").Select("ID = '" & rowID & "'")
        LDTRow(0)("LDTSyntax") = Me.TextBox1.Text
        Me.ResponsibilityMasterBindingSource.EndEdit()
        Me.ResponsibilityMasterTableAdapter.Update(LDTRow(0))
        MsgBox("LDT Syntax has been updated!", MsgBoxStyle.OkOnly, "Commit Success!")
    End Sub
End Class

Any advice on how to do the updates to the table with datasets and tableadapters is GREALTY appreciated. I was working on this from start to finish for about 10 hours yesterday and got hung up on the table update for about 3 of those hours, still with no resolution. I look forward to any advice and recommendations.
 
You have to connect back to the database, and run your update there.

This is usually accomplished with a stored procedure that you pass teh values into.

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top