我正在尝试创建一个搜索,其中 SQL 查询取决于一个单选按钮和一个文本框。表格、文本框和单选按钮都在同一个表单上。我正在使用 Microsoft Visual Studio 2012 for Web,并尝试更改表单上 GridView 对象的数据源。但是,我不断收到错误消息:
ConnectionString 属性尚未初始化。
我怎样才能解决这个问题?下面是我的完整代码。
Protected Sub btnSearch_Click(sender As Object, e As ImageClickEventArgs) Handles btnSearch.Click
Dim sqlQuery As String = ""
If radClient.Checked = True Then
GridView1.Visible = False
sqlQuery = "SELECT * FROM Sales WHERE ClientID = '" & txtSearch.Text & "'"
ElseIf radItem.Checked = True Then
GridView1.Visible = False
sqlQuery = "SELECT * FROM Sales WHERE ItemID = '" & txtSearch.Text & "'"
ElseIf radUser.Checked = True Then
GridView1.Visible = False
sqlQuery = "SELECT * FROM Sales WHERE UserID = '" & txtSearch.Text & "'"
ElseIf radUser.Checked = False And radClient.Checked = False And radItem.Checked = False Then
ErrorLabel.Text = "Error: You have not chosen a search criteria."
Return
End If
SqlDataSource3.SelectCommand = sqlQuery
SqlDataSource3.DataBind()
End Sub
感谢@Steve、@MuhammadOmar、@Westie 和@AmitApollo 对我之前线程中的代码的帮助。
谢谢!