WebMatrix Alternative for SqlCommand.Parameters.Add

82 Views Asked by At

I've used WebMatrix for parameterized query like:

string sql = @"SELECT col FROM table WHERE id = @0 AND name = @1";
db.Query(sql, someID, someName);

But I got stuck on unknown count of parameters. In traditional ADO.NET solution we have SqlCommand.Parameters.Add so we can add parameters one by one programmatically.

Is there any alternative like SqlCommand.Parameters.Add in WebMatrix?

1

There are 1 best solutions below

0
mriiiron On

OK.. I found the solution myself in this blog post. The key point is Database.Query() method accepts an array of Objects.

So given an array of parameters and properly construct the SQL string would do the work.