2

I am currently having trouble trying to get a select command with a session variable in my asp gridview. I have been looking on here and other sites and have not really came across much. It's got to be a simple fix that i just have not came across yet. Here is my code

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:mySql_Connection %>"
                    SelectCommand =  "Select [Username], [Name] FROM UserPassword WHERE CustID = '" & session("CustID") & "'>
                </asp:SqlDataSource>

I'm not even sure if that is close to correct or not. I get the server tag is not well formed. Or invalid syntax. Can someone show how to do this. I've been stuck on this and its really bugging me.

1 Answer 1

2

You can use Session Paramter

<asp:SqlDataSource ConnectionString="<%$ConnectionStrings:mySql_Connection %>"
                SelectCommand =  "Select [Username], [Name] FROM UserPassword WHERE CustID     = @CustID>
 <SelectParameters>
  <asp:SessionParameter Name="CustID" SessionField="CustID"
   DefaultValue="0" />

 </SelectParameters>
</asp:SqlDataSource>

You can refer the below link also: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx

Sign up to request clarification or add additional context in comments.

8 Comments

so what would i do sessionParameter Name = "CustID" SessionField = "CustID"? and would the select command be FROM UserPassword WHERE CustID = CustID">?
made some edits.. in the command give your parameter name starting with with '@'. I do so usually on code behind, but the example in MSDN article given has just a '?'
see i tried that before and got this same thing "Must declare the scalar variable "@CustID"."
can you try just a '?' as given in the MSDN article msdn.microsoft.com/en-us/library/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.