1

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?

2
  • Can't you supply it with an array of objects as the second parameter? Commented Jan 12, 2018 at 21:55
  • @rene Yes you're right.. I found the solution myself. Thanks anyway! Commented Jan 12, 2018 at 22:08

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.