Search code examples
sqlwebmatrixsqlparameter

WebMatrix / WebPages / SQL Compact - Named SQL Parameters


How do you add named SQL Parameters in WebPages Framework?

var db = Database.Open("database");
var stories = db.Query("select * from story where category = @1", 545433);

I only see parameters such as the above code, they are numbers, I want them to have names, something like this:

var db = Database.Open("database");
var stories = db.Query("select * from story where category = @category");

But I don't know how, I googled it, read articles but found the numbered one. How can I add named SQL Parameters?


Solution

  • If you want to use named parameters, don't use the Database helper. It doesn't support them. It works by creating parameter objects from an array of values based on their index in that array. Hence the numbers.