所以用VB创建一个.Net站点并运行MySQL服务器。
尝试在connectionstring
中使用变量来仅检索某些数据。
我目前在标题中:
<script language="vbscript">
Dim varSQLcommand as String
varSQLcommand = "1"
</script>
和
的连接字符串<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:emergency systemsConnectionString3 %>"
ProviderName="<%$ ConnectionStrings:emergency systemsConnectionString3.ProviderName %>"
SelectCommand= "SELECT * from tbldisaster WHERE Disaster_ID = " & varSQLcommand & "" >
</asp:SqlDataSource>
将varSQLcommand = "1"
替换为varSQLcommand = Request.QueryString("ID")
,并将网址设为disasterdetails.aspx?ID={1}
。
这是做我想做的正确方法吗?
答案 0 :(得分:0)
您可以使用SelectParameters
在SQL中设置自定义变量:
SelectCommand="SELECT * FROM tblDisaster WHERE Disaster_ID = @Disaster_ID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="ID" Name="Disaster_ID" />
</SelectParameters>
在这种情况下,过滤条件来自查询字符串(?id=123
),因此我们使用QueryStringParameter
,并将其绑定到名称为@Disaster_ID
的参数。然后,查询将从网址中提取ID值,并将其替换为查询中出现@Disaster_ID
的位置。
答案 1 :(得分:0)
这里还有另一个问题可以帮到你。您可以使用另一个回复中所述的SelectParameters,也可以使用以下代码在代码隐藏中声明它们:
Dim myDisasterID As String = Request.Querystring("id") 'Do whatever you may have to do with the variable SqlDataSource1.SelectParameters.Add("variablename", myDisasterID); SqlDataSource1.SelectCommand = "SELECT * FROM tbldisaster where disasterid=@variablename"