Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SqlDataSource and SelectParameters problem

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Viewers will learn how the fundamental information of how to create a table.
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.
Suggested Courses

610 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