如何使用IfElse执行多个查询字符串?

时间:2017-07-12 05:58:48

标签: string vb.net if-statement odbc

我只想知道如何使用IfElse语句执行多个查询字符串。

我有这个字符串命令和查询:

    Dim dt As New DataTable
    ' Stablish ODBC Connection
    Dim con As New OdbcConnection("DRIVER={SQL Server};Server=WJNJPHR8TCX8P\SQLEXPRESS;Database=Fabrics;Integrated Security=True;")
    ' Query Command
    Dim cmd As New OdbcCommand
    Dim query1 As String = cmd.CommandText = "SELECT * FROM Client WHERE ClientId = ?"
    Dim query2 As String = cmd.CommandText = "SELECT * FROM Client WHERE FirstName = ?"
    Dim query3 As String = cmd.CommandText = "SELECT * FROM Client WHERE FirstName = ? AND MiddleName = ?"
    Dim query4 As String = cmd.CommandText = "SELECT * FROM Client WHERE ClientId = ? AND FirstName = ? AND MiddleName = ?"
    con.Open()

任何人都可以帮我解决这个问题吗?

感谢您提前! :)

1 个答案:

答案 0 :(得分:0)

单独处理每个查询。一次执行一个查询,使用其返回值并将其绘制在网格上,然后接下一个查询,依此类推。