0

我有一个查询,我想使用下面的查询在所有表中搜索一个公共字段 ismy 代码----

   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....?

4

1 回答 1

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 参数 (qv)

于 2013-02-21T20:48:39.443 回答