SQL Datasource with code behind:

Hi all,

I am trying to use a query into the code behind like that: "SELECT SELECT * FROM [ListePage] order by @id desc" the problem is that the errors says that its a non declared for the @id
-------------------------------------------------
System.Data.SqlClient.SqlException: Must declare the variable '@id'.
-------------------------------------------------
If I try to do this:
SqlDataSource1.SelectParameters.Add(new Parameter("@id", TypeCode.String));
SqlDataSource1.SelectCommand = "SELECT * FROM [ListePage] order by @id desc";
In this case I can get rid of the error but I don't get any results (I obtain a page with no result for the query). :(
Any ideas?
Ben
0
benol
4/26/2004 3:51:46 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
987 Views

Similar Articles

[PageSpeed] 52

First, this area is for questions about the next version of .NET. Are you using Whidbey?

Re: your query. I would be surprised it this would run. AFAIK, you can't use a parameter in the ORDER BY clause. Are you sure you don't mean
SELECT * FROM [ListePage]

WHERE [ListePage].ID = @id
ORDER BY desc

Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
4/26/2004 4:14:43 PM
hi,

yes, im under Whidbey
but u are right
the query is :
SqlDataSource1.SelectParameters.Add(new Parameter("@column", TypeCode.String));
SqlDataSource1.SelectCommand = SELECT * FROM table ORDER BY @column DESC";
In this case I can get rid of the error but I don't get any results (I obtain a page with no result for the query).

i dont know how i can specified column name in @column
0
saranghae
4/26/2004 5:30:24 PM
Are you using Yukon? Becasue what I know you can't use a parameter for the ORDER BY in Sql server 2000. By the way, you must set the value of the parameter.

Parameter param = new Parameter("@column", TypeCode.String);
param.DefaultValue = "myValue";
SqlDataSource1.SelectParameters.Add(param);

/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

ASPInsiders
My Blog
0
Fredrik
4/26/2004 6:04:46 PM
Hi,

1 thx a lots
2 No, i dont use Yukon but 2000
3 it doesn't work.
---------------------------------------------------------------------------------------------------
Parameter param = new Parameter("@column", TypeCode.String);
param.DefaultValue = "id";
SqlDataSource1.SelectParameters.Add(param);
SqlDataSource1.SelectCommand = "select * from members order by @column desc";
SqlDataSource1.DataBind();
---------------------------------------------------------------------------------------------------
i obtained this message:
---------------------------------------------------------------------------------------------------Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@column'.
---------------------------------------------------------------------------------------------------
0
saranghae
4/26/2004 11:47:29 PM
You can't use an parameters in ORDER BY, this will probably work in Yukon but not in Sql 2000.


/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

ASPInsiders
My Blog
0
Fredrik
4/27/2004 4:03:49 AM
Reply:

Similar Artilces:

code for Custom paging without using sqldatasource control and sql datasource control for gridview...........
 code for Custom paging without using sqldatasource control and sql datasource control for gridview...........i need code for how to show all pagenumbers in gridview with custom paging in gridview..............It is very urgent................................. T.Ashok Kumar  suppose that we have a table like thisCountryId  identity intCountryTitle    nvarchar(50)you can use this sql command for paging the dataUSE [CyberOffice]GO/****** Object:  StoredProcedure [dbo].[CountryGetListPaged]    Script Date: 09/17/2008 14:01:06 ******/SET A...

Setting width for .net controls in code(.aspx) page using function call in code behind..
Hi,  Currently I am trying to set the width of the asp.net Table as follows. <asp:Table width="<%=GetWidth()%>" >   and code behind protected Unit GetWidth() { return Unit.Percentage(50); }     It's not working. I know that it works if I set the width complete on some page event(like page_load) of code behind....   Is there a way to maintain the same syntax like calling code behind function in design page...i.e. calling function of .aspx.cs in .aspx page and assign the width as shown above.   Thanks and regards, Giridhar...

sql datasource UpdateParameters code behind
 Hi all,i have detailsview bind to sqldatasource (directily) with select and updatecommand. Now i have 3 buttons on my page - resolved, pending, cancelresolved - set status = "success" and comment = "somthing"pending - set status = "inprogress" and comment = "somthing"cancel - shoud close the asppagehow can i set in code behind this updateparameters.DetailsView is bind directly to sqldatasource - in witch event shoud i paste the statement i dont`t know if this is right 'SqlDataSource1.UpdateParameters.Clear()...    &nb...

Moving items from the page code behind to the user control code behind.
I am trying to setup a page with a user control specified as a header. Things work fine until the user control has to access dynamic content that is in the code behind of the main page. When I try to move these commands to the code behind for the user control I get errors saying items have not been declared. What is the best way to do this, I'm mainly trying to create some headers and footers for my asp.net project. if it belongs for the header move it to the headers code behind. It is probably saying items have not been declared because you moved the methods, but not the properties to...

Code behind vrs. non code behind in VS.NET 2003
Does anyone know what the advantages and disadvantages are for using code behind vrs. non code behind in Visual Studio.Net 2003? One important difference is that you are able to separate the design of a web site from the code. This makes for ease of maintainablity and much more structured applications. If you ever worked with classic ASP the code-behind is a great invention. sivilianMy Weblogs...

Dynamic SQL in code behind, access to control parameters?
If I declare control paramters, will I be able to access these in  my code behind for a Dynamic SQL statement>?  Example:  Im building the select statement using a checkboxlist, and wish to be able to filter these results based on 3 dropdownlist.selectedvalues.  So i'll declare the control parameters in the front end, but will I be able to call those in the code behind... Induction_type and Engine_cams being the control parameters. example, I'll append my select statement (strSQL) to the following "Where Induction_Type =" + "@ Induc...

Setting focus on control in the code-behind VB.NET
Hello, Can anyone tell me if you see anything wrong with this code? I'm trying to set focus on txt_job textbox when a button is clicked. 1 Private Sub SetFocusScript(ByVal strTextBox As String) 2 3 Dim sb As New System.Text.StringBuilder() 4 5 sb.Append("<script language='javascript'>") 6 7 sb.Append("document.frmView." & strTextBox & ".focus();") 8 9 sb.Append("</script>") 10 11 ' register the script 12 13 ...

vb.net data controls not found in code behind?
I am trying to follow along some of the very basic tutorials by scott gu but using vb.net.  When I try and databind from my code behind I get an intellisense error that the control cannot be found?  Doesn't matter if it is a listview a repeater or whatever. Here is my code behind:1 Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 2 Repeater1.datasource = ViewData("Categories") 3 Repeater1.databind() 4 End SubHere is my front end aspx: 1 <%@ Page Language="vb" AutoEve...

Accessing Form Controls via code behind (VB.NET)
Hi,I hope someone can help provide some light on this problem I'm having. I have searched the forums and found another post on ASP.NET that references how to access controls on a form using for example:Dim lstResourceServers As WebControl = frmASP.FindControl("lstResourceServers")This will indeed give me access to the listbox control on the form but I can't access the properties and methods specific to the listbox control class such as Items, SelectedIndex, etc. which to me is rather pointless.If I place a listbox or any other component on my asp.net page I can directly acc...

what about the code-behind (code behind)
One MAJOR difference between AJAX.NET and Atlas.NET seems to be that AJAX.NET is able to expose methods in your codebehind to the client. Why doesn't Atlas do this? Or am I mistaken? With AJAX.NET it's just a simple line or two:  Ajax.Utility.RegisterTypeForAjax(GetType(myClass)) <Ajax.AjaxMethod()>Public Function myFunction PLEASE tell me Atlas has something comparable to this. I don't have the time to rewrite all my code-behind methods in javascript or atlas script. All you need to do in Atlas to expose a method on your page (or its code behind class) is to put a [WebMet...

how to add a query to sql datasource using a value from code behind?
 I have a value in my web form which is received from previous page and i have a sqldatasource in which i have written the query through the wizard.In this query i want to use where clause which tallies the cavlue from code behind :the code in code behind is:value1 = Request("abc")SqlDataSource1.SelectParameters("fid").DefaultValue = value1and in source:  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CoursePortalConnectionString %>"       &nb...

Code Behind or not Code Behind
Ok i am confuse now.... A lot of books are showing pages without code behind (the code is integrated in the .aspx) Is it better to use the code behind or not. Is there any difference between using VB.NET or C#.NET except for the code synthax. Thank you and come again. A lot of samples show inline code just for simplicity.. i personally use code-behind because I like to seperate my code from presentation. As for VB.NET or C#, its your preference.. there is no difference really when its all said and done. From a purely mathematical sense, having everything in a single file would s...

how come vs.net doesnt import my controls when i open the code behind?
hi all, when i write the markup for some webcontrols i'm going to use in a webform, how come vs.net doesn't automatically list these elements in the code behind, when i open it up? i don't think i should have to write the declarations myself! is there a way to configure this? VS will sync the declarations if you switch to design view after adding them in HTML view.Tim McBrideThis posting is provided "AS IS" with no warranties, and confers no rights. Is there any better answer?? This same exact problem has been driving me absolutely nuts. I am still very new to .NET. I swear that...

Set Datasource to Drop Down Control in FormView InsertTemplate Field through Code Behind
Hey , How do I set Datasource to Drop Down Control in FormView InsertTemplate/EditItemTemplate Field through Code Behind. I need this as we use general connection objects and general data retrival methods in a common Data Class. Please help? Thanks, Shyam Hi, raghavashyam: You just need to bind the datasource to the FormView(Containers) and the syntax as following in the templateFiled will bind the particlar filed to your controls.  <asp:TemplateField HeaderText="Name" >               &nb...

Web resources about - SQL Datasource with code behind: - asp.net.presentation-controls

Datasource - Wikipedia, the free encyclopedia
A DataSource object has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property ...

Inverness Graham Acquires DataSource
Inverness Graham , a lower middle market private equity firm headquartered in suburban Philadelphia, has acquired DataSource , a print supply ...

SmartGlance for iPad for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about SmartGlance for iPad on the App Store. Download SmartGlance for iPad ...

Chaitanya Pandit (@chaitanyapandit) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Data source - Wikipedia, the free encyclopedia
... Data source A data source is any of the following types of sources for (mostly) digitized data: a database in the Java software platform, datasource ...

2ndQuadrant - PostgreSQL expertise from specialists with a source code level understanding of RDBMS ...
PostgreSQL expertise from specialists with a source code level understanding of RDBMS PostgreSQL Planets Gabriele’s PlanetPostgreSQL Gianni’s ...

Tagged entries for CLOUD COMPUTING
Alan Williamson's output as a Java Champion, Blog-City Architect, BlueDragon Creator, Author, Speaker and Internet Guru

Private equity deals
... of biometric identity management systems, applications and services. www.crossmatch.com Inverness Graham Investment has acquired DataSource ...

C# C Sharp and Tutorials on C# Friends.com
Learn the c# langauge to build web applications using our online tutorials with live demos. Participate in our forums and learn from others. ...

JavaScript UI Library, Ajax Components & HTML5 Framework - DHTMLX
DHTMLX offers a rich JavaScript library, UI components & HTML5 mobile framework. Build impressive web apps for both desktop and mobile devices. ...

Resources last updated: 12/17/2015 10:31:30 AM