我有一个查询,我想在所有表格中搜索公共字段,使用下面的查询ismy code ----
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
'Dim da As OleDb.OleDbDataAdapter
Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
Me.con = New OleDb.OleDbConnection
Dim sqlquery As String = "SELECT * FROM **mba mca mscit** WHERE urno='" & TextBox2.Text & "';"
Dim command As New OleDb.OleDbCommand(sqlquery, con)
Dim reader As OleDb.OleDbDataReader
con.ConnectionString = dbprovider
con.Open()
reader = command.ExecuteReader()
reader.Read()
TextBox1.Text = reader(1).ToString
TextBox2.Text = reader(2).ToString
TextBox3.Text = reader(3).ToString
TextBox4.Text = reader(4).ToString
TextBox5.Text = reader(5).ToString
Catch ex As Exception
MsgBox("Not Found")
con.Close()
End Try
我想在所有表格中搜索urno,其中包含相同名称的字段....?
答案 0 :(得分:0)
假设表mba,mca和mscit具有相同的列,那么
SELECT * FROM mba
WHERE urno=@urno
UNION
SELECT * FROM mca
WHERE urno=@urno
UNION
SELECT * FROM mscit
WHERE urno=@urno
并为@urno
提供SQL参数(q.v.)