Solved

SqlDataSource and SelectParameters problem

Posted on 2009-06-27
4
511 Views
Last Modified: 2012-06-27
Hi,

I try to change an ASP.NET problem from a MDB DataSource to a SQL Server.
Now I've a DataSource with SelectedParameters and don't know how to change it to SQL Server Syntax.

This works fine with a MDB:
<asp:SqlDataSource runat="server" ID="sds2" SelectCommand="SELECT * FROM [Orders] WHERE CustomerID = ?"
 ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Northwind.mdb;" ProviderName="System.Data.OleDb">
    <SelectParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

I tried this, but only get an error message "near ?":
<asp:SqlDataSource runat="server" ID="sds2" SelectCommand="SELECT * FROM [Orders] WHERE CustomerID = ?"
 ConnectionString="server=localhost;database=Northwind;uid=sa;password=lifesuxx;">
    <SelectParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

The connection and the query is fine, just the replacement of the parameter seems to be wrong.
What is the right syntax for?

Thanks,

Andre
0
Comment
Question by:andre72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
nasserd earned 500 total points
ID: 24728034
Try changing ? to @CustomerID and changing Name="CustomerID" to Name="@CustomerID"
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24728060
Try it like this:
ConnectionString="server=localhost;database=Northwind;User ID=sa;Password=lifesuxx;Trusted_Connection=False;"
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24728066
Ah, never mind.  I failed to read the question correctly.
0
 

Author Closing Comment

by:andre72
ID: 31597555
When I was out yet I thought about stored procedures and also about AddWithValue ... However it works fine, thanks!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have a large data set and a SSIS package. How can I load this file in multi threading?
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question