我正在尝试创建一个搜索,其中 SQL 查询取决于一个单选按钮和一个文本框。
SELECT * FROM [Sales] WHERE (text in radio button) = (text in textbox)
我该如何实施?
下面是我的完整代码。
Protected Sub btnSearch_Click(sender As Object, e As ImageClickEventArgs) Handles btnSearch.Click
If radClient.Checked = True Then
Dim connection As New OleDb.OleDbConnection
Dim provider As String
Dim source As String
provider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
source = "Data Source=|DataDirectory|DeltaOneMDB.mdb"
connection.ConnectionString = provider & source
GridView1.Visible = False
connection.Open()
SqlDataSource3.SelectCommand = "SELECT * FROM Sales WHERE ClientID = '" & txtSearch.Text & "'"
connection.Close()
ElseIf radItem.Checked = True Then
Dim connection As New OleDb.OleDbConnection
Dim provider As String
Dim source As String
provider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
source = "Data Source=|DataDirectory|DeltaOneMDB.mdb"
connection.ConnectionString = provider & source
GridView1.Visible = False
connection.Open()
SqlDataSource3.SelectCommand = "SELECT * FROM Sales WHERE ItemID = '" & txtSearch.Text & "'"
connection.Close()
ElseIf radUser.Checked = True Then
Dim connection As New OleDb.OleDbConnection
Dim provider As String
Dim source As String
provider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
source = "Data Source=|DataDirectory|DeltaOneMDB.mdb"
connection.ConnectionString = provider & source
GridView1.Visible = False
connection.Open()
SqlDataSource3.SelectCommand = "SELECT * FROM Sales WHERE UserID = '" & txtSearch.Text & "'"
connection.Close()
ElseIf radUser.Checked = False And radClient.Checked = False And radItem.Checked = False Then
ErrorLabel.Text = "Error: You have not chosen a search criteria."
End If
End Sub
表格、文本框和单选按钮都在同一个表单上。我正在使用 Microsoft Visual Studio 2012 for Web,并尝试更改表单上 GridView 对象的数据源。但是,我不断收到错误消息:
ConnectionString 属性尚未初始化。
很抱歉没有早点给出我的代码。
谢谢!