0

I am new to writing Stored Procedure. So I wrote below procedure and want to access the output values in my program, hot to do it.

My Stored Procedure:

Create Procedure [dbo].[STP_ExecCarInDriver_SelectByCarCode]
@CarCode nchar(10)
As
Begin

SELECT DISTINCT
[MachineName]
,[FirstName]
,[LastName]
FROM [RoadTrs].[dbo].[ViewExecCarInDriver]
WHERE [CarCode]=@CarCode

End

and try with below code to instance to MachineName,FirstName and Last Name parameters:

var Results = rt.STP_ExecCarInDriver_SelectByCarCode(txtCarCode.Text);
string MachineName= Results(0).

but it doesn't work !

Farzad M
  • 67
  • 3
  • 10

2 Answers2

1

if you are using LinqtoSql i would advise against using the stored proceedure at all (they become a pain in the arse to manage imho)

instead use the data context to get the item

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;
}
RoughPlace
  • 1,111
  • 1
  • 13
  • 23
0

Use following:

        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;
KS Tech
  • 194
  • 4