Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So making a .Net site with VB and running off of a MySQL server.

Trying to use a variable within the connectionstring to only retrieve certain data.

I Currently have in the header:

<script language="vbscript">
     Dim varSQLcommand as String

     varSQLcommand = "1"
</script>

and the connection string of

<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>

Going to replace varSQLcommand = "1" with varSQLcommand = Request.QueryString("ID") and make the url disasterdetails.aspx?ID={1}.

is this the Correct way to do what I want to do?

share|improve this question
add comment

3 Answers

You can use the SelectParameters to set custom variables in your SQL:

SelectCommand="SELECT * FROM tblDisaster WHERE Disaster_ID = @Disaster_ID">
    <SelectParameters>
        <asp:QueryStringParameter QueryStringField="ID" Name="Disaster_ID" />
    </SelectParameters>

In this case, the filter criteria comes from the Query String (?id=123), so we use the QueryStringParameter, and bind it to parameter with name @Disaster_ID. Then the query will pull the id value from the url and replace it where @Disaster_ID appears in the query.

share|improve this answer
add comment

The query is run sever side, no javascript changes will get it to do what you want -- at least not directly. You want to use a selectparameter, which is typically set to an object on your page (textbox,menu item),and when that changes your your query is rerun with the new value. You can change the value of the object on your page using javascript if you like, or just let the user do it...

share|improve this answer
add comment

There is another question on here that may help you. You could either use the SelectParameters as stated in another reply, or you could declare them in your code-behind using the following:

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"

Here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.