473,657 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("h dnSelect") %>"

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
8 1985
Hi,

Did you tried:

SelectCommand = Request.Form("h dnSelect").ToSt ring()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@commu nity.nospam> wrote in message
news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"

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
Hi Jacob,

For dynamically setting the DataSource control's select command, we can use
code behind to programmaticall y assign certain values to it as Ignacio has
mentioned. e.g:
protected void Page_Load(objec t sender, EventArgs e)
{
SqlDataSource1. SelectCommand = "Select top 1 * from Categories";
}
Also, if what you want to customize is just some certain select
criterias(param eters), we can also consider using the SqlDataSource's
selectParameter s to deine tha variable and associate those parameter
variables to request.Form colleciton. e.g:

=============== =============== ===
CategoryID > <input type="text" name="cid" value="0" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" /><br />
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:LocalNorthWi nd %>"
SelectCommand=" SELECT [Description], [CategoryName],
[CategoryID] FROM [Categories] WHERE ([CategoryID] > @CategoryID)">
<SelectParamete rs>
<asp:FormParame ter FormField="cid" Name="CategoryI D"
Type="Int32" DefaultValue="4 " />
</SelectParameter s>
</asp:SqlDataSour ce>

=============== ==============

#FormParameter Class
http://msdn2.microsoft.com/en-us/lib...rols.formparam
eter.aspx
Hope also helps.

Thanks & Merry Christmas!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >
| References: <e$************ **@TK2MSFTNGP09 .phx.gbl>
| Subject: Re: Select string building in C# and ASP.NET
| Date: Thu, 22 Dec 2005 13:26:13 -0500
| Lines: 32
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <uS************ *@TK2MSFTNGP12. phx.gbl>
| Newsgroups:
microsoft.publi c.dotnet.framew ork.aspnet,micr osoft.public.do tnet.languages. c
sharp
| NNTP-Posting-Host: 156.75.83.95
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.langua ges.csharp:3737 11
microsoft.publi c.dotnet.framew ork.aspnet:3666 21
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Hi,
|
| Did you tried:
|
| SelectCommand = Request.Form("h dnSelect").ToSt ring()
|
|
|
| --
| Ignacio Machin,
| ignacio.machin AT dot.state.fl.us
| Florida Department Of Transportation
|
|
| "Jacob Arthur" <ja******@commu nity.nospam> wrote in message
| news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"
| >
| > 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
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.mach in AT dot.state.fl.us > wrote
in message news:uS******** *****@TK2MSFTNG P12.phx.gbl...
Hi,

Did you tried:

SelectCommand = Request.Form("h dnSelect").ToSt ring()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@commu nity.nospam> wrote in message
news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"

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
Hi Jacob,

Have you also had a look in my last reply? Also, as for
SqlDataSource.S electCommand , it should be assigned a valid select
statement which will return record set from database, and those records
should contains valid Properties that mapping to the Fields or Columns we
defined in dataBound control (GridView or DetailsView. .....).

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Reply-To: "Jacob Arthur" <jacob-no@--spam-atstn.com>
| From: "Jacob Arthur" <ja******@commu nity.nospam>
| References: <e$************ **@TK2MSFTNGP09 .phx.gbl>
<uS************ *@TK2MSFTNGP12. phx.gbl>
| Subject: Re: Select string building in C# and ASP.NET
| Date: Thu, 22 Dec 2005 21:56:19 -0600
| Lines: 52
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <uQ************ **@tk2msftngp13 .phx.gbl>
| Newsgroups:
microsoft.publi c.dotnet.framew ork.aspnet,micr osoft.public.do tnet.languages. c
sharp
| NNTP-Posting-Host: h460ad645.area7 .spcsdns.net 70.10.214.69
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.langua ges.csharp:3737 96
microsoft.publi c.dotnet.framew ork.aspnet:3667 13
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| 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.mach in AT dot.state.fl.us >
wrote
| in message news:uS******** *****@TK2MSFTNG P12.phx.gbl...
| > Hi,
| >
| > Did you tried:
| >
| > SelectCommand = Request.Form("h dnSelect").ToSt ring()
| >
| >
| >
| > --
| > Ignacio Machin,
| > ignacio.machin AT dot.state.fl.us
| > Florida Department Of Transportation
| >
| >
| > "Jacob Arthur" <ja******@commu nity.nospam> wrote in message
| > news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"
| >>
| >> 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
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******@commu nity.nospam> wrote in message
news:uQ******** ******@tk2msftn gp13.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.mach in AT dot.state.fl.us >
wrote in message news:uS******** *****@TK2MSFTNG P12.phx.gbl...
Hi,

Did you tried:

SelectCommand = Request.Form("h dnSelect").ToSt ring()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@commu nity.nospam> wrote in message
news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"

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 #6
In the code behind file:
static String docList;
protected void Page_Load(objec t sender, EventArgs e)
{
SqlDataSource1. SelectCommand = docList;
}
protected void Button1_Click(o bject sender, EventArgs e)
{
docList = "";
String currDocId = "";
docList = "SELECT DocIdFld, NameFld FROM doctbl WHERE ";

System.Collecti ons.Queue docIDQ = new System.Collecti ons.Queue();
txtDocIDs.Text = txtDocIDs.Text + "\n";
for (int i = 0; i < txtDocIDs.Text. Length; i++)
{
if (Char.IsLetterO rDigit((char)tx tDocIDs.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="S qlDataSource1">
</asp:DataList><a sp:SqlDataSourc e ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ConnectionSt ring %>"
ProviderName="< %$ ConnectionStrin gs:ConnectionSt ring.ProviderNa me %>" >
</asp:SqlDataSour ce>

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.mach in AT dot.state.fl.us > wrote
in message news:Oh******** ******@TK2MSFTN GP12.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******@commu nity.nospam> wrote in message
news:uQ******** ******@tk2msftn gp13.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.mach in AT dot.state.fl.us >
wrote in message news:uS******** *****@TK2MSFTNG P12.phx.gbl...
Hi,

Did you tried:

SelectCommand = Request.Form("h dnSelect").ToSt ring()

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jacob Arthur" <ja******@commu nity.nospam> wrote in message
news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"

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 #7
Hi Jacob,

From the code you provided, the problem seems due to the sequence you build
the select command string and set it to the SqlDataSource's Select Command.
For ASP.NET page, the "Page_Load" event always fire before other
control(like button)'s postback event, so if you generate the new Select
string in postback event, and only set it to SqlDataSource in "page_load" ,
the SqlDataSource's selectCommand is not updated correctly.... Also, after
you update the SqlDataSource's SelectCommand, we'd better recall the
DataBound control( GridView , DetailsView.... )'s DataBind() method so that
they'll repopulate the datas from the DataSource so as to reflect the
changes.....

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Reply-To: "Jacob Arthur" <jacob-no@--spam-atstn.com>
| From: "Jacob Arthur" <ja******@commu nity.nospam>
| References: <e$************ **@TK2MSFTNGP09 .phx.gbl>
<uS************ *@TK2MSFTNGP12. phx.gbl>
<uQ************ **@tk2msftngp13 .phx.gbl>
<Oh************ **@TK2MSFTNGP12 .phx.gbl>
| Subject: Re: Select string building in C# and ASP.NET
| Date: Fri, 23 Dec 2005 11:50:12 -0600
| Lines: 133
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <ue************ *@TK2MSFTNGP14. phx.gbl>
| Newsgroups:
microsoft.publi c.dotnet.framew ork.aspnet,micr osoft.public.do tnet.languages. c
sharp
| NNTP-Posting-Host: 015-952-822.area7.spcsd ns.net 68.242.121.62
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.langua ges.csharp:3738 96
microsoft.publi c.dotnet.framew ork.aspnet:3668 15
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| In the code behind file:
| static String docList;
| protected void Page_Load(objec t sender, EventArgs e)
| {
| SqlDataSource1. SelectCommand = docList;
| }
| protected void Button1_Click(o bject sender, EventArgs e)
| {
| docList = "";
| String currDocId = "";
| docList = "SELECT DocIdFld, NameFld FROM doctbl WHERE ";
|
| System.Collecti ons.Queue docIDQ = new System.Collecti ons.Queue();
| txtDocIDs.Text = txtDocIDs.Text + "\n";
| for (int i = 0; i < txtDocIDs.Text. Length; i++)
| {
| if (Char.IsLetterO rDigit((char)tx tDocIDs.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="S qlDataSource1">
| </asp:DataList><a sp:SqlDataSourc e ID="SqlDataSour ce1" runat="server"
| ConnectionStrin g="<%$ ConnectionStrin gs:ConnectionSt ring %>"
| ProviderName="< %$ ConnectionStrin gs:ConnectionSt ring.ProviderNa me %>" >
| </asp:SqlDataSour ce>
|
| 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.mach in AT dot.state.fl.us >
wrote
| in message news:Oh******** ******@TK2MSFTN GP12.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******@commu nity.nospam> wrote in message
| > news:uQ******** ******@tk2msftn gp13.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.mach in AT dot.state.fl.us >
| >> wrote in message news:uS******** *****@TK2MSFTNG P12.phx.gbl...
| >>> Hi,
| >>>
| >>> Did you tried:
| >>>
| >>> SelectCommand = Request.Form("h dnSelect").ToSt ring()
| >>>
| >>>
| >>>
| >>> --
| >>> Ignacio Machin,
| >>> ignacio.machin AT dot.state.fl.us
| >>> Florida Department Of Transportation
| >>>
| >>>
| >>> "Jacob Arthur" <ja******@commu nity.nospam> wrote in message
| >>> news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"
| >>>>
| >>>> 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 26 '05 #8
Hi Jacob,

Any progress on this? If there're anything else we can help, please feel
free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 21370574
| References: <e$************ **@TK2MSFTNGP09 .phx.gbl>
<uS************ *@TK2MSFTNGP12. phx.gbl>
<uQ************ **@tk2msftngp13 .phx.gbl>
<Oh************ **@TK2MSFTNGP12 .phx.gbl>
<ue************ *@TK2MSFTNGP14. phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online. microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Mon, 26 Dec 2005 02:00:54 GMT
| Subject: Re: Select string building in C# and ASP.NET
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| Message-ID: <A$************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 161
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3669 96
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Jacob,
|
| From the code you provided, the problem seems due to the sequence you
build
| the select command string and set it to the SqlDataSource's Select
Command.
| For ASP.NET page, the "Page_Load" event always fire before other
| control(like button)'s postback event, so if you generate the new Select
| string in postback event, and only set it to SqlDataSource in
"page_load" ,
| the SqlDataSource's selectCommand is not updated correctly.... Also,
after
| you update the SqlDataSource's SelectCommand, we'd better recall the
| DataBound control( GridView , DetailsView.... )'s DataBind() method so
that
| they'll repopulate the datas from the DataSource so as to reflect the
| changes.....
|
| Regards,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
|
| --------------------
| | Reply-To: "Jacob Arthur" <jacob-no@--spam-atstn.com>
| | From: "Jacob Arthur" <ja******@commu nity.nospam>
| | References: <e$************ **@TK2MSFTNGP09 .phx.gbl>
| <uS************ *@TK2MSFTNGP12. phx.gbl>
| <uQ************ **@tk2msftngp13 .phx.gbl>
| <Oh************ **@TK2MSFTNGP12 .phx.gbl>
| | Subject: Re: Select string building in C# and ASP.NET
| | Date: Fri, 23 Dec 2005 11:50:12 -0600
| | Lines: 133
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| | X-RFC2646: Format=Flowed; Response
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| | Message-ID: <ue************ *@TK2MSFTNGP14. phx.gbl>
| | Newsgroups:
|
microsoft.publi c.dotnet.framew ork.aspnet,micr osoft.public.do tnet.languages. c
| sharp
| | NNTP-Posting-Host: 015-952-822.area7.spcsd ns.net 68.242.121.62
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.langua ges.csharp:3738 96
| microsoft.publi c.dotnet.framew ork.aspnet:3668 15
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | In the code behind file:
| | static String docList;
| | protected void Page_Load(objec t sender, EventArgs e)
| | {
| | SqlDataSource1. SelectCommand = docList;
| | }
| | protected void Button1_Click(o bject sender, EventArgs e)
| | {
| | docList = "";
| | String currDocId = "";
| | docList = "SELECT DocIdFld, NameFld FROM doctbl WHERE ";
| |
| | System.Collecti ons.Queue docIDQ = new System.Collecti ons.Queue();
| | txtDocIDs.Text = txtDocIDs.Text + "\n";
| | for (int i = 0; i < txtDocIDs.Text. Length; i++)
| | {
| | if (Char.IsLetterO rDigit((char)tx tDocIDs.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="S qlDataSource1">
| | </asp:DataList><a sp:SqlDataSourc e ID="SqlDataSour ce1" runat="server"
| | ConnectionStrin g="<%$ ConnectionStrin gs:ConnectionSt ring %>"
| | ProviderName="< %$ ConnectionStrin gs:ConnectionSt ring.ProviderNa me %>" >
| | </asp:SqlDataSour ce>
| |
| | 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.mach in AT dot.state.fl.us >
| wrote
| | in message news:Oh******** ******@TK2MSFTN GP12.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******@commu nity.nospam> wrote in message
| | > news:uQ******** ******@tk2msftn gp13.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.mach in AT
dot.state.fl.us >
| | >> wrote in message news:uS******** *****@TK2MSFTNG P12.phx.gbl...
| | >>> Hi,
| | >>>
| | >>> Did you tried:
| | >>>
| | >>> SelectCommand = Request.Form("h dnSelect").ToSt ring()
| | >>>
| | >>>
| | >>>
| | >>> --
| | >>> Ignacio Machin,
| | >>> ignacio.machin AT dot.state.fl.us
| | >>> Florida Department Of Transportation
| | >>>
| | >>>
| | >>> "Jacob Arthur" <ja******@commu nity.nospam> wrote in message
| | >>> news:e$******** ******@TK2MSFTN GP09.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("h dnSelect") %>"
| | >>>>
| | >>>> 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 28 '05 #9

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

Similar topics

15
2732
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 start at the bottom. What seems to plague many ORM systems is the syntactic confusion and string-manipulation required to build the SQL Statements. If you want to do a Left Outer Join, support nested functions, and a nested conditional clause, you'd...
3
6449
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
4
2008
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 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.
5
2554
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 #31/1/2006#" But when I try it from my vb.net app, I get ALL the records in the tabel?? What goes wrong? I haven't been able to find any info on the net, besides others having
2
2121
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 Building Fund
6
2041
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 = hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND hottubs.seatsto <= '%s' AND hottubs.shape = '%s' ORDER BY $thesearchtype_search.
5
13859
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 the dropdown with the value from the database. The value in the database is either new, trial, maint., employee, beta, or null. I need to set the dropdrown to one of these values. An example of the select; <td> <select name="ordReason">...
1
8056
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 a commandbutton on my form). The biggest problem I'm having is that I can't (don't know how) populate a combobox on static items such as "True, False, Any." The Any field, would be selected by the user to find all records where that fields is...
7
2920
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 it shows error page not found on this server i googled and found some people use union and select to hack sites (mysql injection) i guess the server i am using has some kind of filter and if a post string content "union select" ... it simply...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8512
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.