473,385 Members | 1,843 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,385 software developers and data experts.

Select Parameters in SQL data source

Hi,
I'm having a problem inserting a parameter into an SQL Select statement
with <asp:ControlParameter>. This should be very simple, but for some
reason it just isn't working:

<%-- Get username and put it in the textbox --%>
<% Session("UserName") =
HttpContext.Current.User.Identity.Name.ToString%>
<% UserField.Text = Session("UserName")%>

<%-- Display the data --%>
<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" />

<%-- Set up the data source --%>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:dConnect %>"
ProviderName="<%$ ConnectionStrings:dConnect.ProviderName
%>" SelectCommand="SELECT a, b FROM x WHERE username = ?">
<SelectParameters>
<asp:ControlParameter ControlID="UserField"
PropertyName="Text" Type="string" />
</SelectParameters>
</asp:SqlDataSource>

<%-- textbox --%>
<asp:textbox ID="UserField" runat="server"/>

If I hardcode the username into the Select statement, or if I set the
DefaultValue of the ControlParameter, it works ok, but I need to be
able to insert the username of whoever's logged on at the time. I'm
using ODBC and MySQL.

If anyone has any ideas on this I'd be very grateful.

Cheers,

Alan

Aug 28 '06 #1
1 2761
KJ
Include an asp:HiddenField on the page. Configure the ODS to use that
hiddenfield control as source for the input parameter. Before
databinding or calling Select on the ODS, set the Value of the hidden
field. The ODS will use the value from the hiddenfield.

Alan wrote:
Hi,
I'm having a problem inserting a parameter into an SQL Select statement
with <asp:ControlParameter>. This should be very simple, but for some
reason it just isn't working:

<%-- Get username and put it in the textbox --%>
<% Session("UserName") =
HttpContext.Current.User.Identity.Name.ToString%>
<% UserField.Text = Session("UserName")%>

<%-- Display the data --%>
<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" />

<%-- Set up the data source --%>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:dConnect %>"
ProviderName="<%$ ConnectionStrings:dConnect.ProviderName
%>" SelectCommand="SELECT a, b FROM x WHERE username = ?">
<SelectParameters>
<asp:ControlParameter ControlID="UserField"
PropertyName="Text" Type="string" />
</SelectParameters>
</asp:SqlDataSource>

<%-- textbox --%>
<asp:textbox ID="UserField" runat="server"/>

If I hardcode the username into the Select statement, or if I set the
DefaultValue of the ControlParameter, it works ok, but I need to be
able to insert the username of whoever's logged on at the time. I'm
using ODBC and MySQL.

If anyone has any ideas on this I'd be very grateful.

Cheers,

Alan
Aug 29 '06 #2

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

Similar topics

3
by: Bill Cart | last post by:
The oldDb Command does not support Named Parameters. If I am reading them correctly, the docs say that the order of the parameter should match the order they are declared in the Stored Procedure....
1
by: chreo | last post by:
Hello. Does anybody had problem with VB application with MS SQL Database? I have DATAGRID which shows TABLE from DATABASE. Next I add new ROW to TABLE with SQLcommand (stored procedure) ...
3
by: Doug | last post by:
Hi I posted an hour ago from a different pc - about calling a form from another form. now i am having trouble passing the value from a text box (called tb.entryData), from the form called...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
2
by: SFM | last post by:
I just want a simple datareader, that i can read the value returned from a select statement executed on a SQL server 2005 db. The code below should work in, but email= rdr.ToString(); when i...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
18
by: rcoco | last post by:
Hi all, I have a datagrid with Button column select in form of hyperlink. On the same page, I have another datagrid that insert data and one column(Name) has Names of a user that is inserting...
1
by: nclauder | last post by:
Hi all, I have a datagrid with Button column select in form of hyperlink. On the same page, I have another datagrid that insert data and one column(Name) has Names of a user that is inserting...
6
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.