Peter
Peter

Reputation: 13

ASP.NET SqlDataSource parameter declaration in code behind

I'm implementing SqlDataSource in code behind. Here is my code:

var sqlDataSource = new SqlDataSource
                                {
                                    ConnectionString = _constr,
                                    SelectCommand =
                                        "SELECT One, Two FROM Foo WHERE (One = @One) AND (Two = @Two)"
                                };

How to declare parameters and attribute them values in code behind? I've tried to do something like this: sqlDataSource.SelectParameteres.Add("@One", "value"); etc. but it thrown execute scalar error.

Upvotes: 0

Views: 5388

Answers (1)

Royi Namir
Royi Namir

Reputation: 148744

try this

sqlDataSource.SelectParameters.Add(new Parameter("One", System.TypeCode.Int32, recordNo))

Upvotes: 3

Related Questions