473,326 Members | 2,125 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,326 software developers and data experts.

Select string building in C# and ASP.NET

How would I go about using a custom select string that is passed from a form
to the SelectCommand parameter of SqlDataSource?

I tried:
SelectCommand = "<% Request.Form("hdnSelect") %>"

but I got an error about putting <% %> tags in a literal. I tried taking
out the quotes (the " ") and it didn't do any good. I'm trying to use the
built in ASP.NET 2.0 DataList control, but I haven't come up with anything.

Thanks,
Jacob
Dec 22 '05 #1
4 1995
Hi,

Did you tried:

SelectCommand = Request.Form("hdnSelect").ToString()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@community.nospam> wrote in message
news:e$**************@TK2MSFTNGP09.phx.gbl...
How would I go about using a custom select string that is passed from a
form to the SelectCommand parameter of SqlDataSource?

I tried:
SelectCommand = "<% Request.Form("hdnSelect") %>"

but I got an error about putting <% %> tags in a literal. I tried taking
out the quotes (the " ") and it didn't do any good. I'm trying to use the
built in ASP.NET 2.0 DataList control, but I haven't come up with
anything.

Thanks,
Jacob

Dec 22 '05 #2
Just tried something a little different, still no luck.

I tried putting the line
SqlDataSource1.SelectCommand = docList;

In to the Page_Load event to make sure it was getting there and it did
during debugging, but there is no data being pulled back. I traded out the
command for

SqlDataSource1.SelectCommand = "select '1'";

and it still doesn't bring anything back in the datalist. Am I missing
something here possibly?

Jacob

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uS*************@TK2MSFTNGP12.phx.gbl...
Hi,

Did you tried:

SelectCommand = Request.Form("hdnSelect").ToString()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@community.nospam> wrote in message
news:e$**************@TK2MSFTNGP09.phx.gbl...
How would I go about using a custom select string that is passed from a
form to the SelectCommand parameter of SqlDataSource?

I tried:
SelectCommand = "<% Request.Form("hdnSelect") %>"

but I got an error about putting <% %> tags in a literal. I tried taking
out the quotes (the " ") and it didn't do any good. I'm trying to use
the built in ASP.NET 2.0 DataList control, but I haven't come up with
anything.

Thanks,
Jacob


Dec 23 '05 #3
Hi,

is your problem in how to get the request which brings your query, or how to
get the data from the database?

post your entire method (where you get the value of the request, and where
you get your data from the DB)
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@community.nospam> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
Just tried something a little different, still no luck.

I tried putting the line
SqlDataSource1.SelectCommand = docList;

In to the Page_Load event to make sure it was getting there and it did
during debugging, but there is no data being pulled back. I traded out
the command for

SqlDataSource1.SelectCommand = "select '1'";

and it still doesn't bring anything back in the datalist. Am I missing
something here possibly?

Jacob

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:uS*************@TK2MSFTNGP12.phx.gbl...
Hi,

Did you tried:

SelectCommand = Request.Form("hdnSelect").ToString()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@community.nospam> wrote in message
news:e$**************@TK2MSFTNGP09.phx.gbl...
How would I go about using a custom select string that is passed from a
form to the SelectCommand parameter of SqlDataSource?

I tried:
SelectCommand = "<% Request.Form("hdnSelect") %>"

but I got an error about putting <% %> tags in a literal. I tried
taking out the quotes (the " ") and it didn't do any good. I'm trying
to use the built in ASP.NET 2.0 DataList control, but I haven't come up
with anything.

Thanks,
Jacob



Dec 23 '05 #4
In the code behind file:
static String docList;
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = docList;
}
protected void Button1_Click(object sender, EventArgs e)
{
docList = "";
String currDocId = "";
docList = "SELECT DocIdFld, NameFld FROM doctbl WHERE ";

System.Collections.Queue docIDQ = new System.Collections.Queue();
txtDocIDs.Text = txtDocIDs.Text + "\n";
for (int i = 0; i < txtDocIDs.Text.Length; i++)
{
if (Char.IsLetterOrDigit((char)txtDocIDs.Text[i]))
currDocId += (char)txtDocIDs.Text[i];
else if (currDocId != "")
{
docIDQ.Enqueue(currDocId);
currDocId = "";
}
}
if (docIDQ.ToArray().GetLength(0) != 0)
{
for (int i = 0; i < docIDQ.ToArray().GetLength(0); i++)
{
docList = docList + "DocIdFld = " +
((String)docIDQ.ToArray()[i]).ToString();
if (i + 1 < docIDQ.ToArray().GetLength(0))
{
docList = docList + " OR ";
}
}
}
hdnSelect.Value = docList;
Label1.Text = docList;
}

And in the main page file:
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" >
</asp:SqlDataSource>

My query string is getting built fine. The string (docList) is actually
stored to a label which is visible for debugging purposes. If I go out to
Query Analyzer, it brings back the rows that I would expect with the exact
select string pasted into it. For some reason though, it never actually
brings any results back on the server. Do I need to add a
SqlDataSource1.Select() or something similar after changing the select
command in the code-behind file perhaps?

Thanks,
Jacob

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:Oh**************@TK2MSFTNGP12.phx.gbl...
Hi,

is your problem in how to get the request which brings your query, or how
to get the data from the database?

post your entire method (where you get the value of the request, and where
you get your data from the DB)
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@community.nospam> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
Just tried something a little different, still no luck.

I tried putting the line
SqlDataSource1.SelectCommand = docList;

In to the Page_Load event to make sure it was getting there and it did
during debugging, but there is no data being pulled back. I traded out
the command for

SqlDataSource1.SelectCommand = "select '1'";

and it still doesn't bring anything back in the datalist. Am I missing
something here possibly?

Jacob

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:uS*************@TK2MSFTNGP12.phx.gbl...
Hi,

Did you tried:

SelectCommand = Request.Form("hdnSelect").ToString()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@community.nospam> wrote in message
news:e$**************@TK2MSFTNGP09.phx.gbl...
How would I go about using a custom select string that is passed from a
form to the SelectCommand parameter of SqlDataSource?

I tried:
SelectCommand = "<% Request.Form("hdnSelect") %>"

but I got an error about putting <% %> tags in a literal. I tried
taking out the quotes (the " ") and it didn't do any good. I'm trying
to use the built in ASP.NET 2.0 DataList control, but I haven't come up
with anything.

Thanks,
Jacob



Dec 23 '05 #5

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

Similar topics

15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
8
by: Jacob Arthur | last post by:
How would I go about using a custom select string that is passed from a form to the SelectCommand parameter of SqlDataSource? I tried: SelectCommand = "<% Request.Form("hdnSelect") %>" but I...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
5
by: Henning M | last post by:
Hi all, I having some problems with Access and selecting records between dates.. When I try this in access, it works fine!! "Select * from Bilag Where Mdates Between #1/1/2006# And...
2
by: johnhanis | last post by:
I'm using a Visual Basic front end with an SQL query to select some data from a MS Access database. I have a table named Tithes with Columns of TitheDate Tither No Total Tithes Faith Promise...
6
by: alex.kemsley | last post by:
Hi guys, I have the following sql statemant to search a mysql database that gets if values from a form with combo box's in. SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =...
5
by: =?Utf-8?B?bWNhdWxpZmZl?= | last post by:
I have an old application ( pre-VB5) that I need to add a select/option list to. This is an edit program so the values for the form will be retrieved from a database. How do I set the value of...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.