0

你好朋友这里是我的代码

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()

数据仅在 datagrid 视图中获取第二个表数据。我想从两个表中加载数据

请帮忙

4

1 回答 1

0

您需要加入两个表cmd.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"
于 2012-04-14T11:53:30.083 回答