我有2个表:tblstudentbasicinfo
和tblzipcode
。
tblstudentbasicinfo
具有以下列
TagID
,Surname
,Firstname
,Middlename
,Course
,Year
,District
,ZipCode
和ContacactNo
tblzipcode
具有以下列
ZipCode
,Province
,Municipality
和District
当学生输入信息时,用户可以根据tblzipcode
中的内容键入地区名称和该地区的邮政编码。
我的问题是当我尝试填充列表视图以显示带有列的学生基本信息时
TagID
,Surname
,Firstname
,Middlename
,Course
,Year
,ZipCode
,Province
,Municipality
,District
和ContactNo
数据不会显示。
这是我尝试过的SQL查询:
Dim sql As String = "Select TagID,Surname,Firstname,Middlename,Course,Year,ZipCode,Province,Municipality,District,Contactno from tblstudentbasicinfo AS t1 Inner Join tblzipcode AS t2 On t1.ZipCode = t2.ZipCode and t1.District = t2.District"
但是我得到了错误:
字段列表中的“邮政编码”列不明确。
im是sql和vb的新功能。有人可以告诉我该如何解决?预先谢谢你
这是我在vb上的代码:
Private Sub Populatelstbasicinfo(TagID As String, Surname As String, Firstname As String, Middlename As String, Course As String, Year As String, ZipCode As String, Province As String, Municipality As String, District As String, contactno As String)
Dim row As String() = New String() {TagID, Surname, Firstname, Middlename, Course, Year, ZipCode, Province, Municipality, District, contactno}
lstbasicinfo.Items.Add(item)
End Sub
Private Sub Retrieve()
lstbasicinfo.Items.Clear()
Dim sql As String = "Select TagID,Surname,Firstname,Middlename,Course,Year,t1.ZipCode,Province,Municipality,t2.Barangay,Contactno from tblstudentbasicinfo AS t1 Inner Join tblzipcode AS t2 On t1.ZipCode = t2.ZipCode and t1.Barangay = t2.Barangay"
cmd = New OdbcCommand(sql, con)
Try
con.Open()
adapter = New OdbcDataAdapter(cmd)
adapter.Fill(dt)
For Each row In dt.Rows
Populatelstbasicinfo(row(0), row(1), row(2), row(3), row(4), row(5), row(6), row(7), row(8), row(9), row(10), row(11), row(12), row(13), row(14), row(15), row(16))
Next
con.Close()
dt.Rows.Clear()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
答案 0 :(得分:0)
编写查询时,您应该学习良好的做法。因此,请考虑以下问题:
Select bi.TagID, bi.Surname, bi.Firstname, bi.Middlename, bi.Course, bi.Year,
z.ZipCode, z.Province, z.Municipality, z.District, bi.Contactno
from tblstudentbasicinfo bi Inner Join
tblzipcode z
on bi.ZipCode = z.ZipCode and bi.District = z.District;
注意: