如何将来自不同表的列连接到一个datagridview? [英] How to join columns from different table into one datagridview?

查看:91
本文介绍了如何将来自不同表的列连接到一个datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有2个表,它有一个列..我想要的是加入这两个表中的特定列..

在表1中我有4列,即ID ,姓氏,名字,

和表2我有4列提示,备注,投诉。



那么我怎么能这样做?非常感谢!



我的尝试:



我不我真的有这个想法。

I have a 2 tables in my database and it has a column.. What I want is to join the specific columns from these 2 tables..
In table 1 I have 4 columns namely ID, Surname, First name,
and in table 2 I have 4 columns TIP, Remarks , Complain.

So how can I do that? Thank a lot!

What I have tried:

I dont really have an idea to do this.

推荐答案

从tb01选择* er

内部联接tb02 ro on er.ID = ro.TIP



首先你没有提到什么类型的加入。哪一个是主键和外键。如果你提供更多信息,我们很容易回答。请尝试上面的解决方案。
Select * from tb01 er
inner join tb02 ro on er.ID=ro.TIP

First Thing you havent mentioned what type of join. And Which one is primary key and foreign key.It would be easy for us to answer if you provide more info .Still try for above solution.


我试着搜索,我得到了。我得到了正确的结果!



I tried to search and this I got. I got a correct result!

Imports System.Data.SqlClient
Public Class OverallPatientRecords

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub OverallPatientRecords_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim conn As New SqlConnection("data source=.\sqlexpress;database=NEWCMO;integrated security=true")
        Dim cmd As SqlCommand = conn.CreateCommand()
        cmd.CommandText = "SELECT p.patientID,t.billingID,t.treatmentID,t.Balance, p.Surname,p.Firstname,p.[middle name],p.Date,p.Age,p.gender from tblRegPatient p,tblPayment t  where p.patientID = t.patientID "
        Dim adapter As New SqlDataAdapter()
        Dim ds As New DataSet()
        adapter.SelectCommand = cmd
        conn.Open()
        adapter.Fill(ds, "tblPayment")
        conn.Close()
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "tblPayment"
    End Sub
End Class


这篇关于如何将来自不同表的列连接到一个datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆