Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webmatrix and Stored Procedures

I'm fooling around with WebMatrix, and so far the best way I've figured out how to use stored procedures with Razor/WebMatrix is like so-

@if (IsPost) {

   var LinkName = Request["LinkName"];
   var LinkURL  = Request["LinkURL"];

   string sQ = String.Format("execute dbo.myprocname @LinkName=\"{0}\",
 @LinkURL=\"{1}",LinkName, LinkURL);

   db.Execute(sQ);
}

Note, I'm not doing any sort of checking for SQL injections or anything like that, which I think would be uber necessary. Am I missing something?

like image 686
infocyde Avatar asked Sep 15 '10 17:09

infocyde


People also ask

Can Tableau run a stored procedure?

Tableau does not perform any transaction management for stored procedures.

What are stored procedures?

What is a Stored Procedure? A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.

Does vertica have stored procedures?

Stored procedures in Vertica can also operate on objects that require higher privileges than that of the caller. An optional parameter allows procedures to run using the privileges of the definer, allowing callers to perform sensitive operations in a controlled way.

What are views and stored procedures?

Definition. A View represents a virtual table. You can join multiple tables in a view and use the View to present the data as if the data were coming from a single table. A Stored Procedure is precompiled database query that improves the security, efficiency and usability of database client/server applications.


1 Answers

The Execute method accepts parameters.

@if (IsPost) {
  var LinkName = Request["LinkName"];
  var LinkURL = Request["LinkURL"];
  string SQL = "exec dbo.myprocname @0, @1";
  db.Execute(SQL, LinkName, LinkURL);
}

Update: I've updated my answer so that the parameters for the sproc are given placeholders that are numbered rather than named.

like image 63
Larsenal Avatar answered Nov 25 '22 13:11

Larsenal