How to update two table with a single Grid

WinForms

ComponentOne's WinForms controls

How to update two table with a single Grid

  • rated by 0 users
  • This post has 1 Reply |
  • 0 Followers
  • I have two tables with one-to-one relationship between them. I want to present the fields from both tables on a single grid and allow users to edit some fields of both tables. However, when issusing DataApapter.Update command, I got an error which indicates that a SQL syntax problem generated by command builder. Any idea? Thanks

    Here is the code I used to connect the grid

    ds = New DataSet

    adap = New PsqlDataAdapter("Select a.Field1, a.Field2,b.Field1,b.Field2 From TableA a Inner Join Table B b On a.Key = b.Key", conn)

    bldr = New PsqlCommandBuilder(adap)

    adap.UpdateCommand = bldr.GetUpdateCommand

    adap.Fill(ds, "TableAB")

    C1DBGrid.DataSource = ds

    C1DBGrid.DataMember = "TableAB"

     

  • Hello,

    You can try using the following snippet of code:

    ·           BEGIN CODE#
    Imports System.Data.SqlClient

     

    Public Class Form1

        Dim myDA As SqlDataAdapter

        Dim myDataSet As DataSet

     

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

            Dim con As SqlConnection = New SqlConnection("Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|\SqlDatabase.mdf")

            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM AccessPage", con)

            con.Open()

            myDA = New SqlDataAdapter(cmd)

            'Automatically generates DeleteCommand, UpdateCommand and InsertCommand for DataAdapter object

            Dim builder As SqlCommandBuilder = New SqlCommandBuilder(myDA)

     

            myDataSet = New DataSet()

            myDA.Fill(myDataSet, "MyTable")

           Me.C1TrueDBGrid1.DataSource = myDataSet.Tables("MyTable").DefaultView

     

            con.Close()

            con = Nothing

        End Sub

       

        ' Save data from DataGridView into Database

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Me.Validate()

            Me.myDA.Update(Me.myDataSet.Tables("MyTable"))

            Me.myDataSet.AcceptChanges()

        End Sub

     

    End Class

    END CODE#

    Hope this helps.

    C1_GaryB.

    <youdao> wrote in message news:218777@10.0.1.98...

    I have two tables with one-to-one relationship between them. I want to present the fields from both tables on a single grid and allow users to edit some fields of both tables. However, when issusing DataApapter.Update command, I got an error which indicates that a SQL syntax problem generated by command builder. Any idea? Thanks

    Here is the code I used to connect the grid

    ds = New DataSet

    adap = New PsqlDataAdapter("Select a.Field1, a.Field2,b.Field1,b.Field2 From TableA a Inner Join Table B b On a.Key = b.Key", conn)

    bldr = New PsqlCommandBuilder(adap)

    adap.UpdateCommand = bldr.GetUpdateCommand

    adap.Fill(ds, "TableAB")

    C1DBGrid.DataSource = ds

    C1DBGrid.DataMember = "TableAB"

     



    http://helpcentral.componentone.com/cs/forums/p/79492/218777.aspx#218777

Page 1 of 1 (2 items)