我正在通过代码绑定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。如何显示Type而不是ID?
答案 0 :(得分: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'