Reputation: 131
I want to call a stored procedure in my Linq code. When I use only one parameter, it works fine, but when I want to use multiple parameters, it shows an error.
Here is what I have done - this work fine:
SqlParameter param1 = new SqlParameter("@Value1", val);
var abc = db.tablename.SqlQuery("SP_Name @Value1", param1).ToList();
Now I want to add second parameter
SqlParameter param2 = new SqlParameter("@Value2", val2);
var abc = db.tablename.SqlQuery("SP_Name @Value1,@Value2", param1, param2 ).ToList();
it returns an error:
An error occurred while reading from the store provider's data reader. See the inner exception for details.
Upvotes: 0
Views: 9196
Reputation: 448
This is how I used the stored procedure with 2 parameters you can use as per your need.
adxGYMDataContext db = new adxGYMDataContext();
var mysp = db.sp_memb_info_get_del(int.Parse(txt_id_memb.Text), true).Select(x=>x).ToList();
foreach (var item in mysp)
{
cmb_duration_memb.Text = item.memb_dur.ToString();
txt_tel_memb.Text = item.memb_tel.ToString();
}
Upvotes: 0
Reputation: 795
Hope this sample code helps you!!
var param1 = new SqlParameter();
param1.ParameterName = "@Value1";
param1.SqlDbType = SqlDbType.Int;
param1.SqlValue = val1;
var param2 = new SqlParameter();
param2.ParameterName = "@Value2";
param2.SqlDbType = SqlDbType.NVarChar;
param2.SqlValue = val2;
var result = db.tablename.SqlQuery("SP_Name @Value1,@Value2", param1, param2 ).ToList();
Upvotes: 3