我想添加一个Url参数。
例如:http://localhost:65319/Example.aspx?FirstName=value
这是我目前的代码
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
Dim dt As New DataTable
Using con As New OdbcConnection("DRIVER={SQL Server};Server=WJNJPHR8TCX8P\SQLEXPRESS;Database=Fabrics;Integrated Security=True;"),
cmd As New OdbcCommand("SELECT * FROM [Client] WHERE OR [FirstName] = ?", con)
con.Open()
cmd.Parameters.Add("@FirstName", OdbcType.NVarChar).Value = FNameTextBox.Text
dt.Load(cmd.ExecuteReader())
End Using
GridView1.DataSourceID = Nothing
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
答案 0 :(得分:0)
您可以咨询MSDN- How to: Pass Values Between ASP.NET Web Forms Pages
您可以查看查询字符串部分并执行以下操作:
cmd.Parameters.Add("@FirstName", OdbcType.NVarChar).Value = Request.QueryString("FirstName")
甚至更好,添加一些验证以确保填充FirstName:
If Not Request.QueryString("FirstName") Is Nothing Then
cmd.Parameters.Add("@FirstName", OdbcType.NVarChar).Value = Request.QueryString("FirstName")
Else
????
End If