473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SELECT Statement Parameter

Hi. I am trying to use an sqldatasource to query a database with parameters. I am setting the sqldatasource up in the ASP section, but want to apply the parameter in the code behind when a hyperlink is pressed in c#.

The ASP section is like this :

<asp:SqlDataSource ID="dsROP" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
ProviderName="<%$ ConnectionStrings:MyConnectionString.ProviderName %>"
SelectCommand="SELECT First_Name, Surname FROM tblStaff WHERE LoginId = @LoginId">
<SelectParameters><asp:Parameter Name="@LoginId" Type=Int32 /></SelectParameters>
</asp:SqlDataSource>



I am not sure how to get the value of the users login (eg 463) into the parameter in the c# code behind. I get an error Must declare the scalar variable "@LoginId with whatever I try.

I am using a SQL Server 2005 database.

ANy help would be appreciated.

Regards
Jul 10 '07 #1
3 1868
jhardman
3,406 Expert 2GB
I'm not sure I follow. If you have a variable named LoginId that youwant to put into to query, then it goes like this:
Expand|Select|Wrap|Line Numbers
  1.         SelectCommand="SELECT First_Name, Surname FROM tblStaff WHERE LoginId = " & LoginId
or if loginId is a form variable, then it looks like this:
Expand|Select|Wrap|Line Numbers
  1.         SelectCommand="SELECT First_Name, Surname FROM tblStaff WHERE LoginId = " & request.form("LoginId")
Is this what you are asking?

Jared
Jul 11 '07 #2
I'm not sure I follow. If you have a variable named LoginId that youwant to put into to query, then it goes like this:
Expand|Select|Wrap|Line Numbers
  1.         SelectCommand="SELECT First_Name, Surname FROM tblStaff WHERE LoginId = " & LoginId
or if loginId is a form variable, then it looks like this:
Expand|Select|Wrap|Line Numbers
  1.         SelectCommand="SELECT First_Name, Surname FROM tblStaff WHERE LoginId = " & request.form("LoginId")
Is this what you are asking?

Jared
Thanks for replying. I want to declare the sqldatasource on the ASP Section of the page with a parameter (LoginId). Then at a later time, be able to apply a value to the parameter in the code behind section (c#).

I know I could do it all in the code behind, but I have read that if you set it up in the ASP bit, the paging is all handled for you.

I hope this makes it clearer to what I am trying to achieve.

Thanks and regards
Jul 11 '07 #3
Thanks for replying. I want to declare the sqldatasource on the ASP Section of the page with a parameter (LoginId). Then at a later time, be able to apply a value to the parameter in the code behind section (c#).

I know I could do it all in the code behind, but I have read that if you set it up in the ASP bit, the paging is all handled for you.

I hope this makes it clearer to what I am trying to achieve.

Thanks and regards
I have now sorted this out. The problem was not with the above, but to do with my connection string - I had a kind of hybrid between a SQL datasource and an OLEDB one.

Many thanks anyway and sorry if I wasted any time.

Regards
Jul 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
2
by: GIS Analyst | last post by:
Hi to all I wish to be able to have a standard select statement which has additional fields added to it at run-time based on supplied parameter(s). ie declare @theTest1 nvarchar(10) set...
6
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best...
3
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
3
by: kscdavefl | last post by:
I am using the following select statement in a web app where I take the cvalue in a text box and conduct a search of the database. "Select wo18 from workorder where wo9 = " + "'" +...
3
by: Brian Conway | last post by:
I am trying to get a parameter passed from one page to another in a QueryString to get inserted into the select statement on the page that is getting called. If I hard code in a value everything...
7
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise...
5
by: Han Lim | last post by:
Dear All, I have an application written by VB.Net with connect to a Microsoft Access database. One of the forms is to select data using oleAdapter and fill it into a dataset. In the oleAdapter, i...
1
by: VB Programmer | last post by:
I have a SqlDataSource I setup on an ASP.NET 2.0 webform. I setup the SELECT statement and it has 1 parameter, @ProductId. How do I, using VB.NET, store the results of that SELECT statement...
2
by: paulmitchell507 | last post by:
I think I am attempting a simple procedure but I just can't figure out the correct syntax. My asp (classic) page runs a SELECT query to obtain dates and ID's from 2 tables uSQL = "SELECT...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.