473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Selectcommand Variable

Hello, I'm wondering why a variable in my selectcommand is not
working.

In Page_Load I have this:

String current_user = User.Identity.Name;
Response.Write(current_user); // verified the string 'djohnson' is
present

But this errors out in the Body ('No value given for one or more
required parameters'):
<asp:AccessDataSource id="AccessDataSource1" runat="server" DataFile =
"upload.mdb" SelectCommand="Select * from Customers WHERE
Login=@current_user"/>

When the username is hard-coded it works fine:
<asp:AccessDataSource id="AccessDataSource1" runat="server" DataFile =
"upload.mdb" SelectCommand="Select * from Customers WHERE
Login='djohnson'"/>

I don't understand it. This is getting frustrating.

May 14 '07 #1
1 3953
You need to supply a value for the @current_user using the SelectParameters
collection and the Selecting event handler.

<asp:AccessDataSource ....>
<SelectParameters>
<asp:Parameter Direction="Input" Name="current_user" Type="string" />
</SelectParameters>
</asp:AccessDataSource>

Define a handler for the Selecting event of the AccessDataSource and assign
the value for current_user:

protected void AccessDataSource_Selecting (object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["current_user"] = <value>;
}
"Dave" wrote:
Hello, I'm wondering why a variable in my selectcommand is not
working.

In Page_Load I have this:

String current_user = User.Identity.Name;
Response.Write(current_user); // verified the string 'djohnson' is
present

But this errors out in the Body ('No value given for one or more
required parameters'):
<asp:AccessDataSource id="AccessDataSource1" runat="server" DataFile =
"upload.mdb" SelectCommand="Select * from Customers WHERE
Login=@current_user"/>

When the username is hard-coded it works fine:
<asp:AccessDataSource id="AccessDataSource1" runat="server" DataFile =
"upload.mdb" SelectCommand="Select * from Customers WHERE
Login='djohnson'"/>

I don't understand it. This is getting frustrating.

May 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Celmer | last post by:
My datagrid has a dataset that has only one table that is populated with a given SelectCommand->Text. I want to change the SelectCommand->Text so that the datagrid displays updated data with a...
0
by: Gancy | last post by:
Hi, I have data access tier designed in such a way, just by changnging application settings, same lines of code is made to work with both MS SQL Server or MS Access. Code works fine with MS SQL...
0
by: Tammy B | last post by:
Hiya How do I programatically set the selectcommand? Select col1, col2 from TABLE_1 next time I want it to be Select col1, col2 from TABLE_2 I won't know which table till runtime
2
by: phil | last post by:
Hi, I want to put a recordset in a gridview but i don't know how to pass the value of the variable in the 'where' statement. The value of the variable is set in the code-behind. i added a tag...
0
by: mlfblom | last post by:
Hi, I know I am not the only one struggling with the following, but so far I have not seen a solution. Problem: I have an asp.net 2.0 web page with a gridview which is bound to an...
4
by: googlegroup | last post by:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionString:SalesDBConnectionString %>" SelectCommand="<%=strSQL%>" /> In ASP.NET , how do you assign a dynamic...
1
by: John Kotuby | last post by:
Hello again... I have tried using the SQLDatsource control as part of a user control that just conatins a Repeater and the SQLDatasource control which is designated as the Datsource for the...
4
by: djohnson | last post by:
Hello, I'm wondering why a variable in my selectcommand is not working. In Page_Load I have this: String current_user = User.Identity.Name; Response.Write(current_user); // verified the...
5
by: =?Utf-8?B?SGFycnkgVg==?= | last post by:
I'm using a StringBuilder to build a SelectCommand string that returns a number of records. If that number is >0, I want to fill an arraylist with fields from the records for a listbox. Is it...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.