?
Solved

SqlDataSource and SelectParameters problem

Posted on 2009-06-27
4
Medium Priority
?
514 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

762 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