S
Stephanie
I am trying to get started with ado.net, coming from experience with ado. I
have a simple SQL Server stored procedure which inserts a row and returns
the value of the identity column for the inserted row (seel below).
I have a method in a C# project which is simply going to add a record and
return the identity. I am looking throught the documentation to see how to
do this.
You see I have a dataadapter and a dataset. But I cannot see what methods to
use to execute the sp and get back tha value.
Can anyone point me in the right direction?
public String add(DateTime entryDate, DateTime startTime, DateTime
endTime, String shortDescription, String longDescription)
{
SqlConnection cn = new SqlConnection("Data Source=sstowe;Initial
Catalog=Time;User ID=sa;Password=password;");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
cn.Open;
da. <--- WHAT now?
da.Fill(ds);
return <--- I think I used to know how to work
}
CREATE PROCEDURE Entry_Add
@EntryDate datetime,
@StartTime datetime,
@EndTime datetime,
@Short char(50),
@Description varchar(255),
@ID int OUTPUT
AS
BEGIN
SET NOCOUNT ON
INSERT INTO Entry
(
EntryDate,
StartTime,
EndTime,
Short,
Description
)
VALUES
(
@EntryDate,
@StartTime,
@EndTime,
@Short,
@Description
)
SELECT @ID = SCOPE_IDENTITY()
END
GO
have a simple SQL Server stored procedure which inserts a row and returns
the value of the identity column for the inserted row (seel below).
I have a method in a C# project which is simply going to add a record and
return the identity. I am looking throught the documentation to see how to
do this.
You see I have a dataadapter and a dataset. But I cannot see what methods to
use to execute the sp and get back tha value.
Can anyone point me in the right direction?
public String add(DateTime entryDate, DateTime startTime, DateTime
endTime, String shortDescription, String longDescription)
{
SqlConnection cn = new SqlConnection("Data Source=sstowe;Initial
Catalog=Time;User ID=sa;Password=password;");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
cn.Open;
da. <--- WHAT now?
da.Fill(ds);
return <--- I think I used to know how to work
}
CREATE PROCEDURE Entry_Add
@EntryDate datetime,
@StartTime datetime,
@EndTime datetime,
@Short char(50),
@Description varchar(255),
@ID int OUTPUT
AS
BEGIN
SET NOCOUNT ON
INSERT INTO Entry
(
EntryDate,
StartTime,
EndTime,
Short,
Description
)
VALUES
(
@EntryDate,
@StartTime,
@EndTime,
@Short,
@Description
)
SELECT @ID = SCOPE_IDENTITY()
END
GO