Update Data from data set and table adapter

esilva002

Member
Joined
Jun 16, 2010
Messages
6
Programming Experience
1-3
I have a windows form program that pulls data from a sql server. That same data is being read from a ASP.NET website that sets properties for the site. The SQL server has 3 tables: tblWebPage, tblObjects, tblProperties. and 6 views for the 6 web page: vWebPage01, vWebPage02, vWebPage03..ect. When the program loads you see buttons for each web page on the site. When the user clicks on the Home Page it loads this data:

VB.NET:
    'Instantiate the class to set the shared values
    Dim Other As New OtherInfo

    'Create Dataset
    Private cDataSet As New RockwareWeb

    'Create Table Adapter
    Private cDataSetTA As New RockwareWebTableAdapters.vWebPage01TableAdapter

    'Create Binding Source
    Private cBindingSource As New BindingSource

    Private Sub frmPage14_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Variables
        Dim ctr1 As Integer = 0
        Dim ctr2 As Integer = 0
        Dim View As String

        'Set up the datagrid for locating records only
        Me.dgView.AllowUserToAddRows = False
        Me.dgView.AllowUserToDeleteRows = False
        Me.dgView.ReadOnly = True
        Me.dgView.AllowUserToResizeRows = False

        'Set controls visible/invisible
        Call SetView(False)

        'Build combo box items
        Do Until ctr1 = OtherInfo.tabColors.Length

            Me.cboForeColor.Items.Add(OtherInfo.colors(ctr1))

            If ctr1 <= 1 Then
                Me.cboVisible.Items.Add(OtherInfo.Visibility(ctr1))
            End If

            If ctr1 <= 2 Then
                Me.cboBorderStyle.Items.Add(OtherInfo.BorderStyle(ctr1))
            End If

            If ctr1 <= 1 Then
                Me.cboFontBold.Items.Add(OtherInfo.Visibility(ctr1))
            End If

            ctr1 = ctr1 + 1
        Loop

        'Reset counter
        ctr2 = frmHome.ButtonCount

        'Find correct table
        For ctr1 = 0 To ctr2
            If frmHome.btnPage14.Text = ProgramInfo.rSiteInfo(1, ctr1) Then
                View = ProgramInfo.rSiteInfo(0, ctr1)
            End If
        Next

        Try
            'Fill the dataset with data
            cDataSet.EnforceConstraints = False
            cDataSetTA.Connection.ConnectionString = ProgramInfo.rConnectionString
            cDataSetTA.Fill(cDataSet.vWebPage01)

            'Set the binding source to the new table
            cBindingSource.DataSource = cDataSet
            cBindingSource.DataMember = "v" & View

            'Bind the datagrid and hide non-essential columns and headers
            Me.dgView.DataSource = cBindingSource
            Me.dgView.Columns(0).Visible = False
            Me.dgView.Columns(2).Visible = False
            Me.dgView.Columns(3).Visible = False
            Me.dgView.Columns(4).Visible = False
            Me.dgView.Columns(5).Visible = False
            Me.dgView.Columns(6).Visible = False
            Me.dgView.Columns(7).Visible = False
            Me.dgView.Columns(8).Visible = False
            Me.dgView.Columns(9).Visible = False
            Me.dgView.Columns(10).Visible = False
            Me.dgView.ColumnHeadersVisible = False

            'Bind the detail controls
            Me.txtText.DataBindings.Add("Text", cBindingSource, "proText")
            Me.numHeight.DataBindings.Add("Value", cBindingSource, "proHeight")
            Me.numWidth.DataBindings.Add("Value", cBindingSource, "proWidth")
            Me.cboForeColor.DataBindings.Add("Text", cBindingSource, "proForeColor")
            Me.cboBorderStyle.DataBindings.Add("Text", cBindingSource, "proBorderStyle")
            Me.numFontSize.DataBindings.Add("Value", cBindingSource, "proFontSize")
            Me.cboFontBold.DataBindings.Add("Text", cBindingSource, "proFontBold")
            Me.cboVisible.DataBindings.Add("Text", cBindingSource, "proVisible")

            ' Set default values to columns in the dataset that are bound to controls that 
            ' do not allow null values. E.g. numeric UpDowns and check boxes
            cDataSet.vWebPage01.Columns("proText").DefaultValue = ""
            cDataSet.vWebPage01.Columns("proHeight").DefaultValue = 0
            cDataSet.vWebPage01.Columns("proWidth").DefaultValue = 0
            cDataSet.vWebPage01.Columns("proForeColor").DefaultValue = ""
            cDataSet.vWebPage01.Columns("proBorderStyle").DefaultValue = ""
            cDataSet.vWebPage01.Columns("proFontSize").DefaultValue = 0
            cDataSet.vWebPage01.Columns("proFontBold").DefaultValue = ""
            cDataSet.vWebPage01.Columns("proVisible").DefaultValue = ""

        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Critical, "Rockware Web Interface 2.0 Error")

        End Try

    End Sub

And then when I Hit the update button I have this code:

VB.NET:
        Try
            'Apply changes to data
            cBindingSource.EndEdit()

            'Update data
            cDataSetTA.Update(cDataSet.vWebPage01)

            'Change form view
            Call SetView(False)

            'Refill the table adapter
            cDataSetTA.Fill(cDataSet.vWebPage01)

        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Critical, "Rockware Web Interface 2.0 Error")

        End Try

Now, the problem lies in updating vWebPage02, vWebPage03, ect.. I assume with the same data I can copy my form with the code and change the form name and the data set to build and update. So that's just what I did changed the form name where needed and changed "vWebPage01" to "vWebPage02".
When I tested the program My "vWebPage01" form it built and updated no problem. when I went to test "vWebPage02" it built the dataset and table adapter fine but it did not update at all.
Anyone have any ideas? Thanks in ahead of time.
 
cDataSetTA.Update(cDataSet.vWebPage01)
So you changed vWebPage01 to vWebPage02, but what does cDataSetTA refer to?
Private cDataSetTA As New RockwareWebTableAdapters.vWebPage01TableAdapter
 
I also changed it there too

Changed:
Private cDataSetTA As New RockwareWebTableAdapters.vWebPage01TableAdapter

To This:
Private cDataSetTA As New RockwareWebTableAdapters.vWebPage02TableAdapter

and in the Table adapter I have the specified StoredProcedure to run with the collection of variables needed. Everything looks great but when updating it runs through the line of code no problem,
VB.NET:
cDataSetTA.Update(cDataSet.vWebPage02)
Doesn't give me an error while debugging it line by line.
 

Latest posts

Back
Top