我是编写存储过程的新手。所以我写了下面的程序,想要访问我程序中的输出值,热点就可以了。
我的存储过程:
Create Procedure [dbo].[STP_ExecCarInDriver_SelectByCarCode]
@CarCode nchar(10)
As
Begin
SELECT DISTINCT
[MachineName]
,[FirstName]
,[LastName]
FROM [RoadTrs].[dbo].[ViewExecCarInDriver]
WHERE [CarCode]=@CarCode
End
并尝试使用以下代码实例到MachineName,FirstName和Last Name参数:
var Results = rt.STP_ExecCarInDriver_SelectByCarCode(txtCarCode.Text);
string MachineName= Results(0).
但它不起作用!
答案 0 :(得分:1)
如果您使用的是LinqtoSql,我建议您不要使用存储的进程 (他们成为了管理imho的痛苦)
而是使用数据上下文来获取项目
int carcode = 0; //input your code here
var ctx = new RoadTrsDataContext();
var item - ctx.ViewExecCarInDriver.Where(x=>x.CarCode == carcode).FirstOrDefault();
ctx.Dispose();
if(item!= null)
{
var name = item.FirstName;
}
答案 1 :(得分:0)
使用以下内容:
var Results = rt.STP_ExecCarInDriver_SelectByCarCode(txtCarCode.Text).FirstOrDefault();//Use .List() if query return more than one result.
string MachineName = Results.MachineName;
string FirstName = Results.FirstName;
string LastName = Results.LastName;