简体   繁体   English

从MS Access的多个表中获取数据到vb.net中的datagrid视图中

[英]Fetching data from multiple table of MS Access into datagrid view in vb.net

Hello friends here is my code 您好朋友,这是我的代码

connect()
        cmd.CommandText = "Select RegID,Name,EmailID,DOB,State,Nation,Contact1 As Contact,ParmanentAdd as Address,Religion,WillNo as WillNumber,Will from SelfInformation"
        cmd.Connection = cn
        dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        tb.Clear()
        tb.Load(dr)
        DataGridView1.DataSource = tb
        cmd.Dispose()
        cn.Close()

        'family.........

connect()
        'cmd.CommandText = "Select RegID,FName As Father,MName As Mother,MStatus As Marital,Degree,Childran As Children,NOC As NumberOfChild from Faimly"
        'cmd.CommandType = CommandType.Text
        'cmd.Connection = cn
        'dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        'tb.Clear()
        'tb.Load(dr)
        'DataGridView1.DataSource = tb
        'cmd.Dispose()
        'cn.Close()

the data is only fetching the second table data in datagrid view .i want to load data from both the tables 数据仅在datagrid视图中获取第二个表数据。我想从两个表中加载数据

please help 请帮忙

You need to join two tables in cmd.CommandText and load it into DataGridView. 您需要在cmd.CommandTextcmd.CommandText两个表并将其加载到DataGridView中。

cmd.CommandText = "Select si.RegID,si.Name,si.EmailID,si.DOB,si.State,si.Nation,si.Contact1 As Contact, " & _
           "si.ParmanentAdd as Address,si.Religion,si.WillNo as si.WillNumber,si.Will," & _
           "f.FName as Father, f.MName as Mother, f.MStatus as Marital, f.Degree, f.Childran As Children, f.NOC As NumberOfChild " & _
           " FROM SelfInformation si, Family f WHERE si.RegID = f.RegID"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM