can i Connect multi table on the datagridView


please answer me can i connect multi table with dataGridview
if can give me example

thanks



Answer this question

can i Connect multi table on the datagridView

  • zz2

    this is an example with a combox and a datagrid

    when u select an item in the combox ,the datagrid will show the item's detail information.

    there are two tables in NorthWind ,order and orderdetail,u can test



  • James CACN

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

    Dim dsOrdersAndDetails As New DataSet()

    Dim daOrders As New SqlClient.SqlDataAdapter()

    Dim daDetails As New SqlClient.SqlDataAdapter()

    Dim conn As New SqlClient.SqlConnection()

    Dim tblOrders As New DataTable()

    Dim tblDetails As New DataTable()

    dsOrdersAndDetails.Tables.Add(tblOrders)

    dsOrdersAndDetails.Tables.Add(tblDetails)

    conn.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI"

    daOrders.SelectCommand = New SqlClient.SqlCommand("Select * From Orders", conn)

    daDetails.SelectCommand = New SqlClient.SqlCommand("Select * From [Order Details]", conn)

    conn.Open()

    daOrders.Fill(tblOrders)

    daDetails.Fill(tblDetails)

    conn.Close()

    Dim rltOrdersToDetails As DataRelation

    rltOrdersToDetails = New DataRelation("Orders_To_Details", _

    tblOrders.Columns("OrderID"), _

    tblDetails.Columns("OrderID"))

    dsOrdersAndDetails.Relations.Add(rltOrdersToDetails)

    cmbMaster.DataSource = tblOrders

    cmbMaster.DisplayMember = "CustomerID"

    dgDetail.DataSource = tblOrders

    dgDetail.DataMember = "Orders_To_Details"

    End Sub



  • Gunston

    You can bind the datagrid to a view that is say a join of two table. As far as I know you can only bind a datagridview to a single datasource.


  • pcd

    You have couple of options...

    Either add RowValidated/RowValidated/RowEnte/RowLeave etc. handlers to the grid and manage updates and inserts to your datatable from those handlers.

    ... Or, do not allow the user edit the values in the grid in place - instead provide them with a different Form where they can enter values and you manage update/insert of rows in your different tables accordingly...

    Sorry - I don't have any sample code that I can share with you.


  • Tom v E

    Up



  • Esprit

    ok that's is true but in update operation or insert operation what i make to do

    plz send me example


  • can i Connect multi table on the datagridView