i want to view data from two tables into one DataGridView like this picture
i work on visual basic.Net 2005
my database is student_database
we have 2 tables : the frst one is student and it has 2 columns number1,name1
the second one is phone and it has 2 columns number1, phonenumber
this is my form
this is my code
when i run this program, just student table displayed
and i want two tables to be displayed like the first picture
can anyone help me and i am sorry for my language
i work on visual basic.Net 2005
my database is student_database
we have 2 tables : the frst one is student and it has 2 columns number1,name1
the second one is phone and it has 2 columns number1, phonenumber
this is my form
this is my code
VB.NET:
Imports System.Data
Imports System.Data.OleDb
Public Class تجربة
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection
Dim myds As New DataSet()
Dim sql0 As String = "select number1,name1 from student"
Dim sql1 As String = "select number1,phonenumber from phone"
con = New OleDbConnection("Provider=Microsoft.ace.OLEDB.12.0;Data Source=student_database.accdb")
Try
Dim dastudent As New OleDb.OleDbDataAdapter(sql0, con)
Dim daphone As New OleDb.OleDbDataAdapter(sql1, con)
dastudent.Fill(myds, "student")
daphone.Fill(myds, "phone")
Dim r As DataRelation = New DataRelation("student-phone", myds.Tables("student").Columns("number1"), myds.Tables("phone").Columns("number1"), True)
myds.Relations.Add(r)
DataGridView1.DataSource = myds.Tables("student")
Catch el As OleDbException
Label1.Text = el.Message
End Try
End Sub
End Class
when i run this program, just student table displayed
and i want two tables to be displayed like the first picture
can anyone help me and i am sorry for my language
Last edited: