Stored Procedure Output Paramter

T

Tamer Ibrahim

Hi,
I'm writing a web application using Scott Mitchell's Data Access Tutorials
as my principal guide.
In my BLL I'm trying to write a AddGiftItem method that has ItemCode as an
output paramter
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert,
true)]

public string AddGiftItem(string title, string detail, DateTime createdOn,
Byte sectionID, string categoryID)

{

DataSetViewGrp.GiftItemsDataTable giftItems = new
DataSetViewGrp.GiftItemsDataTable();

DataSetViewGrp.GiftItemsRow giftItem = giftItems.NewGiftItemsRow();

if (title == null) giftItem.SetTitleNull(); else giftItem.Title = title;

if (detail == null) giftItem.SetDetailNull(); else giftItem.Detail = detail;

giftItem.CreatedOn = createdOn;

giftItem.SectionID = sectionID;

giftItem.CategoryID = categoryID;

giftItems.AddGiftItemsRow(giftItem);

string itemCode = Adapter.Update(giftItems).ToString();

return itemCode ;

}

and here is my stored procedure that do the insert

ALTER PROCEDURE dbo.spGiftItemsInsert

(

@Title nvarchar(300),

@Detail nvarchar(4000),

@CreatedOn datetime,

@SectionID tinyint,

@ItemCode nvarchar(6) output,

@CategoryID nvarchar(2)

)

AS

SET NOCOUNT OFF;

BEGIN TRAN

INSERT INTO [Contents] ([Title], [Detail], [CreatedOn], [SectionID]) VALUES
(@Title, @Detail, @CreatedOn, @SectionID);

INSERT INTO GiftItems (ContentID, ItemCode, CategoryID) VALUES
(SCOPE_IDENTITY(),dbo.fnItemCode(@CategoryID),@CategoryID);


SET @ItemCode = dbo.fnItemCode(@CategoryID);

COMMIT TRAN

How can I get this work out ?

Thank You.
 
G

Guest

Hi,
I'm writing a web application using Scott Mitchell's Data Access Tutorials
as my principal guide.
In my BLL I'm trying to write a AddGiftItem method that has ItemCode as an
output paramter
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.Data­ObjectMethodType.Insert,
true)]

public string AddGiftItem(string title, string detail, DateTime createdOn,
Byte sectionID, string categoryID)

{

DataSetViewGrp.GiftItemsDataTable giftItems = new
DataSetViewGrp.GiftItemsDataTable();

DataSetViewGrp.GiftItemsRow giftItem = giftItems.NewGiftItemsRow();

if (title == null) giftItem.SetTitleNull(); else giftItem.Title = title;

if (detail == null) giftItem.SetDetailNull(); else giftItem.Detail = detail;

giftItem.CreatedOn = createdOn;

giftItem.SectionID = sectionID;

giftItem.CategoryID = categoryID;

giftItems.AddGiftItemsRow(giftItem);

string itemCode = Adapter.Update(giftItems).ToString();

return itemCode ;

}

and here is my stored procedure that do the insert

ALTER PROCEDURE dbo.spGiftItemsInsert

(

@Title nvarchar(300),

@Detail nvarchar(4000),

@CreatedOn datetime,

@SectionID tinyint,

@ItemCode nvarchar(6) output,

@CategoryID nvarchar(2)

)

AS

SET NOCOUNT OFF;

BEGIN TRAN

INSERT INTO [Contents] ([Title], [Detail], [CreatedOn], [SectionID]) VALUES
(@Title, @Detail, @CreatedOn, @SectionID);

INSERT INTO GiftItems (ContentID, ItemCode, CategoryID) VALUES
(SCOPE_IDENTITY(),dbo.fnItemCode(@CategoryID),@CategoryID);

SET @ItemCode = dbo.fnItemCode(@CategoryID);

COMMIT TRAN

How can I get this work out ?

Thank You.

Hi Tamer,

What is the problem here exactly? Does your stored procedure work (you
can check it against database)? Does your code return an error?
 
M

Murtaza Iqbal Gandhi

Tamer said:
Hi,
I'm writing a web application using Scott Mitchell's Data Access Tutorials
as my principal guide.
In my BLL I'm trying to write a AddGiftItem method that has ItemCode as an
output paramter
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert,
true)]

public string AddGiftItem(string title, string detail, DateTime createdOn,
Byte sectionID, string categoryID)

{

DataSetViewGrp.GiftItemsDataTable giftItems = new
DataSetViewGrp.GiftItemsDataTable();

DataSetViewGrp.GiftItemsRow giftItem = giftItems.NewGiftItemsRow();

if (title == null) giftItem.SetTitleNull(); else giftItem.Title = title;

if (detail == null) giftItem.SetDetailNull(); else giftItem.Detail = detail;

giftItem.CreatedOn = createdOn;

giftItem.SectionID = sectionID;

giftItem.CategoryID = categoryID;

giftItems.AddGiftItemsRow(giftItem);

string itemCode = Adapter.Update(giftItems).ToString();

return itemCode ;

}

and here is my stored procedure that do the insert

ALTER PROCEDURE dbo.spGiftItemsInsert

(

@Title nvarchar(300),

@Detail nvarchar(4000),

@CreatedOn datetime,

@SectionID tinyint,

@ItemCode nvarchar(6) output,

@CategoryID nvarchar(2)

)

AS

SET NOCOUNT OFF;

BEGIN TRAN

INSERT INTO [Contents] ([Title], [Detail], [CreatedOn], [SectionID]) VALUES
(@Title, @Detail, @CreatedOn, @SectionID);

INSERT INTO GiftItems (ContentID, ItemCode, CategoryID) VALUES
(SCOPE_IDENTITY(),dbo.fnItemCode(@CategoryID),@CategoryID);


SET @ItemCode = dbo.fnItemCode(@CategoryID);

COMMIT TRAN

How can I get this work out ?

Thank You.
your problem must be that you havent passed an

itemcode empty parameter

check it using a parameter for itemcode
and direction as output
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top