Can you clarify on that? your code looks good, are you sure your Select statement is correct? Are you sure the Sessionfield Utilizador contains a value?
Maybe you could try to set the Type Property of the SessionParameter...
Try replacing @SelectUser with ?. Otherwise I can't see anything wrong with your code.
Since OleDb parameters (which I'm sure that he's using [:D] ) are not recognized by their name, chancing the parameter name will not solve anything!
"no value found for one or more needed parameters". This error ussualy occurs when a fieldname (or tablename) in the SQL string is misspelled. Access (or better said Jet) will thread this misspelled (not existing) fieldname as a parameter. If you've access
on you computer, try to run the SQL statement in Access. Access will prompt you for every non existing fieldname, I think it will not only prompt you for the parameter @SelectUser but also for 1 or more other misspelled fieldnames....
Marked as answer by voliveira on Jun 12, 2009 02:24 AM
You might be right hans, but if you read the link you provided in a different post (namely
http://msdn.microsoft.com/en-us/library/8e5545e1.aspx), you'll see that they say you're supposed to use ? as parameter placeholder; it's under the "Using Parameters
with the AccessDataSource Control" section. Perhaps it's not absolutely necessary...
Good point, but I'm sure that's absolutely not necessary, a simple test will convince you that this is not true! The reason can be found in the same MSDN article:
"The AccessDataSource control inherits the SqlDataSource class and replaces the ConnectionString property with a DataFile property to make it more convenient to connect to a Microsoft Access database"
So if named parameters cannot be used, they could not be used with as SqlDataSource either! The only difference in OleDb between named parameters and ? is that every ? is threaded as a different parameter, and named parameters that are used multiple times
are threaded as 1
voliveira
Member
37 Points
63 Posts
Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 12:11 AM|LINK
I'd like to know how I can use a session variable inside the SelectCommand of an asp:AccessDataSource control.
ASP code:
<asp:AccessDataSource ID="dSrcMarcacoes" runat="server" DataFile="~/App_Data/Clinica.mdb" SelectCommand="SELECT COLABORADORES.NOME_COLAB, MARCACOES.DATA, MARCACOES.HORA, MARCACOES.SALA FROM ((MARCACOES INNER JOIN COLABORADORES ON MARCACOES.ID_MEDICO = COLABORADORES.ID_COLABORADOR) INNER JOIN PACIENTES ON MARCACOES.ID_PACIENTE = PACIENTES.ID_PACIENTE) WHERE (MARCACOES.ID_PACIENTE = @SelectUser)"> <SelectParameters> <asp:SessionParameter Name="SelectUser" SessionField="Utilizador" /> </SelectParameters> </asp:AccessDataSource>The above code does not work - I simply want the where clause to be defined by the Session Variable "Utilizador" - not using codebehind!AccessDataSource SelectCommand GridView session variable
Mark as answer if my reply is somewhat insightful. Or helped you in any way!
hans_v
All-Star
35986 Points
6550 Posts
Re: Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 01:08 AM|LINK
Can you clarify on that? your code looks good, are you sure your Select statement is correct? Are you sure the Sessionfield Utilizador contains a value?
Maybe you could try to set the Type Property of the SessionParameter...
voliveira
Member
37 Points
63 Posts
Re: Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 01:44 AM|LINK
I am sure there is a stored variable - I am using it on a label before.
My doubt resides in the
Mark as answer if my reply is somewhat insightful. Or helped you in any way!
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 01:53 AM|LINK
Try replacing @SelectUser with ?. Otherwise I can't see anything wrong with your code.
hans_v
All-Star
35986 Points
6550 Posts
Re: Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 02:09 AM|LINK
Since OleDb parameters (which I'm sure that he's using [:D] ) are not recognized by their name, chancing the parameter name will not solve anything!
"no value found for one or more needed parameters". This error ussualy occurs when a fieldname (or tablename) in the SQL string is misspelled. Access (or better said Jet) will thread this misspelled (not existing) fieldname as a parameter. If you've access on you computer, try to run the SQL statement in Access. Access will prompt you for every non existing fieldname, I think it will not only prompt you for the parameter @SelectUser but also for 1 or more other misspelled fieldnames....
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 02:22 AM|LINK
You might be right hans, but if you read the link you provided in a different post (namely http://msdn.microsoft.com/en-us/library/8e5545e1.aspx), you'll see that they say you're supposed to use ? as parameter placeholder; it's under the "Using Parameters with the AccessDataSource Control" section. Perhaps it's not absolutely necessary...
voliveira
Member
37 Points
63 Posts
Re: Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 02:24 AM|LINK
..Misspelling indeed.
Thanks for all the help.
Working code (created a new session variable and passed pacient ID instead of name - no blanks between words on where clause)
<asp:AccessDataSource ID="dSrcMarcacoes" runat="server" DataFile="~/App_Data/Clinica.mdb" SelectCommand="SELECT COLABORADORES.NOME_COLAB, MARCACOES.DATA, MARCACOES.HORA, MARCACOES.SALA FROM ((MARCACOES INNER JOIN COLABORADORES ON MARCACOES.ID_MEDICO = COLABORADORES.ID_COLABORADOR) INNER JOIN PACIENTES ON MARCACOES.ID_PACIENTE = PACIENTES.ID_PACIENTE) WHERE (PACIENTES.ID_PACIENTE = @SelectUser)"> <SelectParameters> <asp:SessionParameter Name="SelectUser" SessionField="usrId" DefaultValue="0" Type="String" /> </SelectParameters> </asp:AccessDataSource>Mark as answer if my reply is somewhat insightful. Or helped you in any way!
hans_v
All-Star
35986 Points
6550 Posts
Re: Submitting session parameters into a select command on a asp.datasource
Jun 12, 2009 02:34 AM|LINK
Good point, but I'm sure that's absolutely not necessary, a simple test will convince you that this is not true! The reason can be found in the same MSDN article:
"The AccessDataSource control inherits the SqlDataSource class and replaces the ConnectionString property with a DataFile property to make it more convenient to connect to a Microsoft Access database"
So if named parameters cannot be used, they could not be used with as SqlDataSource either! The only difference in OleDb between named parameters and ? is that every ? is threaded as a different parameter, and named parameters that are used multiple times are threaded as 1