Solved

SqlDataSource and SelectParameters problem

Posted on 2009-06-27
4
507 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
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

930 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

12 Experts available now in Live!

Get 1:1 Help Now