1

我正在通过代码绑定gridview,我遇到的问题是显示的列之一是另一个表的外键,因此显示了整数值。是否有一种可能的方式来显示该外键的文本值?

这就是我所做的:

     Dim cmd As New SqlCommand("SELECT ID, Customer, ContactPerson, Model, SerialNo, Status, Type, Value, InvoiceNo" &
                                  " FROM BackBillCustomer WHERE Status = 'Open'", cn)
        cn.Open()
            Dim rs As SqlDataReader = cmd.ExecuteReader()

            If rs.HasRows Then
                Dim adp As New SqlDataAdapter(cmd)
                Dim ds As New DataSet()
                rs.Close()
                adp.Fill(ds, "CustMeter")
                gvMeter.AllowPaging = True
                gvMeter.PageSize = (10)
                gvMeter.DataSource = ds
                gvMeter.DataBind()

                gvMeter.Attributes.Add("style", "word-break:keep-all;word-wrap:normal")
            Else
                rs.Close()

“类型”列是外键。在这个表中只有两行 ID 和 Type。如何显示类型而不是 ID?

4

1 回答 1

1

试试这个查询...

SELECT a.ID, Customer, ContactPerson, Model, SerialNo, Status, b.Type, Value, InvoiceNo
     FROM BackBillCustomer a inner join ForegnKeyTableName b  on a.Type=B.id and Status = 'Open'
于 2013-06-27T07:42:33.437 回答