none
vb net error binding in datagridview RRS feed

  • Question

  • I have 2 tables Table_1 master, Table_2 detail and 2 datagridviews, this code only shows in datagridview2 the detail table which must be the master table and datagridview3 shows nothing

     Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
             Dim binding As New BindingSource
            Dim bindingd As New BindingSource
            Dim b As New SqlConnectionStringBuilder
            Dim a As String
            b.DataSource = ComboBox1.Text.ToString
            b.IntegratedSecurity = True
            b.InitialCatalog = ComboBox2.Text.ToString
    
            Dim SQL As String = ("SELECT * FROM Table_1 N INNER JOIN (select * from TABLE_2) d1 ON N.ID = d1.id2 order by N.id")
            Dim conn As New SqlConnection
            conn.ConnectionString = b.ToString
            ' open the connection
            'Create a SqlDataAdapter object
            Dim adapter1 As SqlDataAdapter = New SqlDataAdapter(SQL, conn)
    
            ' Call DataAdapter's Fill method to fill data from the
            ' Data Adapter to the DataSet
            Dim ds As New DataSet
           
            conn.Open()
            adapter1.Fill(ds, "Table_1")
            adapter1.Fill(ds, "Table_2")
            conn.Close()
            binding.DataSource = ds
            binding.DataMember = "Table_1"
            DataGridView2.DataSource = binding
            bindingd.DataSource = ds
            bindingd.DataMember = "Table_2"
            bindingd.DataSource = "Table_1"
            DataGridView3.DataSource = bindingd
    
        End Sub

    any help.

    Saturday, December 21, 2019 6:57 PM

All replies