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

Problems with Parameters and SQLDataSource

Hi, I'm having problems to get the value of a Querystring into the
SelectCommand of a SQLDataSource, here's my code:

----------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%'
+ @nombre + '%'">

<SelectParameters>
<asp:QueryStringParameter Name="nombre"
QueryStringField="nombre" type="string" DefaultValue=""/>
</SelectParameters>

</asp:SqlDataSource>

-----------------------------------------------
Here is the URL that call that code....

http://localhost:8103/MySQL_Test/def...?nombre=daniel

------------------------------------------------

The SelectCommand is not working right, is like the @nombre weren't
returning any value even if I set a default value

I have tried this commands with no result...
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' + @nombre + '%'

-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' & @nombre & '%'

-SELECT cedula,nombre,tipo FROM clientes WHERE nombre=@nombre

If I set the querystring value directly into the SelectCommand the query
return the expected result:
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%daniel%'

What's wrong with my code?

--
DRH
Jul 19 '06 #1
3 8910
in the aspx (this example is for the northwind sample database):

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
SelectCommand="SELECT * FROM [Customers] WHERE
([ContactName] LIKE @ContactName)"
OnSelecting="SqlDataSource1_Selecting">
<SelectParameters>
<asp:QueryStringParameter Name="ContactName"
QueryStringField="Name" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

in the codebehind (this is C#):

protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["@ContactName"].Value = "%" +
e.Command.Parameters["@ContactName"].Value + "%";
}

what you want to do is handle the selecting event, and wrap the
parameter value in the % wildcards

also, don't use dynamic SQL

Daniel R. H. wrote:
Hi, I'm having problems to get the value of a Querystring into the
SelectCommand of a SQLDataSource, here's my code:

----------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%'
+ @nombre + '%'">

<SelectParameters>
<asp:QueryStringParameter Name="nombre"
QueryStringField="nombre" type="string" DefaultValue=""/>
</SelectParameters>

</asp:SqlDataSource>

-----------------------------------------------
Here is the URL that call that code....

http://localhost:8103/MySQL_Test/def...?nombre=daniel

------------------------------------------------

The SelectCommand is not working right, is like the @nombre weren't
returning any value even if I set a default value

I have tried this commands with no result...
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' + @nombre + '%'

-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' & @nombre & '%'

-SELECT cedula,nombre,tipo FROM clientes WHERE nombre=@nombre

If I set the querystring value directly into the SelectCommand the query
return the expected result:
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%daniel%'

What's wrong with my code?

--
DRH
Jul 19 '06 #2
My DB in MySQL, is that a reason for my problem?

--
DRH
"ne**********@gmail.com" wrote:
in the aspx (this example is for the northwind sample database):

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
SelectCommand="SELECT * FROM [Customers] WHERE
([ContactName] LIKE @ContactName)"
OnSelecting="SqlDataSource1_Selecting">
<SelectParameters>
<asp:QueryStringParameter Name="ContactName"
QueryStringField="Name" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

in the codebehind (this is C#):

protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["@ContactName"].Value = "%" +
e.Command.Parameters["@ContactName"].Value + "%";
}

what you want to do is handle the selecting event, and wrap the
parameter value in the % wildcards

also, don't use dynamic SQL

Daniel R. H. wrote:
Hi, I'm having problems to get the value of a Querystring into the
SelectCommand of a SQLDataSource, here's my code:

----------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%'
+ @nombre + '%'">

<SelectParameters>
<asp:QueryStringParameter Name="nombre"
QueryStringField="nombre" type="string" DefaultValue=""/>
</SelectParameters>

</asp:SqlDataSource>

-----------------------------------------------
Here is the URL that call that code....

http://localhost:8103/MySQL_Test/def...?nombre=daniel

------------------------------------------------

The SelectCommand is not working right, is like the @nombre weren't
returning any value even if I set a default value

I have tried this commands with no result...
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' + @nombre + '%'

-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' & @nombre & '%'

-SELECT cedula,nombre,tipo FROM clientes WHERE nombre=@nombre

If I set the querystring value directly into the SelectCommand the query
return the expected result:
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%daniel%'

What's wrong with my code?

--
DRH

Jul 19 '06 #3
yes it is

1. sqldatasource is for ms sql server

2. parameter declarations different in mysql

Daniel R. H. wrote:
My DB in MySQL, is that a reason for my problem?

--
DRH
"ne**********@gmail.com" wrote:
in the aspx (this example is for the northwind sample database):

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
SelectCommand="SELECT * FROM [Customers] WHERE
([ContactName] LIKE @ContactName)"
OnSelecting="SqlDataSource1_Selecting">
<SelectParameters>
<asp:QueryStringParameter Name="ContactName"
QueryStringField="Name" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

in the codebehind (this is C#):

protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["@ContactName"].Value = "%" +
e.Command.Parameters["@ContactName"].Value + "%";
}

what you want to do is handle the selecting event, and wrap the
parameter value in the % wildcards

also, don't use dynamic SQL

Daniel R. H. wrote:
Hi, I'm having problems to get the value of a Querystring into the
SelectCommand of a SQLDataSource, here's my code:
>
----------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%'
+ @nombre + '%'">
>
<SelectParameters>
<asp:QueryStringParameter Name="nombre"
QueryStringField="nombre" type="string" DefaultValue=""/>
</SelectParameters>
>
</asp:SqlDataSource>
>
-----------------------------------------------
Here is the URL that call that code....
>
http://localhost:8103/MySQL_Test/def...?nombre=daniel
>
------------------------------------------------
>
The SelectCommand is not working right, is like the @nombre weren't
returning any value even if I set a default value
>
I have tried this commands with no result...
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' + @nombre + '%'
>
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' & @nombre & '%'
>
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre=@nombre
>
If I set the querystring value directly into the SelectCommand the query
return the expected result:
-SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%daniel%'
>
What's wrong with my code?
>
--
DRH
Jul 19 '06 #4

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

Similar topics

1
by: realgeek | last post by:
I have the following code: SqlDataSource ds = new SqlDataSource(); ds.ConnectionString = WebConfigurationManager.ConnectionStrings.ToString(); ds.UpdateCommand = "ad_SetAnswer";...
5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
4
by: marti | last post by:
I've run into three problems trying to solve this one issue. Using VS2005 B2 & sql server 2000, I create a sqldatasource and bind a gridview to it. Everything looks good. However, if there is an...
2
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them...
1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
0
by: Steven Blair | last post by:
Here is my problem. This is using a FormView and a SqlDataSource. On Updating, I need to compare the old values (orignal values returned from Database) against the updated values. If there are...
3
by: djc | last post by:
I am playing with the (new to me) sqlDataSource class. I used it to bind data from a database table into a listbox with no code, worked great. Now I need to do an INSERT for every item in a...
1
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end...
2
by: Brad Isaacs | last post by:
Good evening friends, I have added a Drop Down List box control to my web form. I am using the web.config connection string to access my SQL Server 2000 db. Inside that db I have a table named...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...
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
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...
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
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...

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.