Solved

SqlDataSource and SelectParameters problem

Posted on 2009-06-27
4
498 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
  • 2
4 Comments
 
LVL 4

Accepted Solution

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

Expert Comment

by:Anthony Perkins
Comment Utility
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
Comment Utility
Ah, never mind.  I failed to read the question correctly.
0
 

Author Closing Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now