Friday, February 24, 2012

can anybody tell me why the following stored procedure is not inserting into my database t

ALTER PROCEDUREAddListAndReturnNewIDValue (

@.EditorIdint,

@.CategoryIDint,

@.ListTitlenvarchar(50),

@.Blurbnvarchar(250),

@.FileNamenvarchar(50),

@.ByLinenvarchar(50),

@.HTMLCopynvarchar(MAX),

@.MainStorybit,

@.MainStoryImageFilenvarchar(50),

@.Publishbit,

@.PublishDatesmalldatetime,

@.ListIdint OUTPUT

)

AS

-- Insert the record into the database

INSERT INTOshortlist (EditorId,CategoryID,ListTitle,Blurb,FileName,ByLine,HTMLCopy,MainStory,MainStoryImageFile,Publish,PublishDate)

VALUES(@.EditorID,@.CategoryID,@.ListTitle,@.Blurb, @.FileName, @.ByLine, @.HTMLCopy, @.MainStory, @.MainStoryImageFile,@.Publish,@.PublishDate)

-- Read the just-inserted ProductID into @.NewProductID

SET@.ListId =SCOPE_IDENTITY()

here is the sqlDataSource

<asp:SqlDataSource

id="srcShortList"

ConnectionString="<%$ ConnectionStrings:ShortList %>"

SelectCommand="SELECT Id,EditorId,CategoryID,ListTitle,Blurb,FileName, ByLine, HTMLCopy, MainStory, MainStoryImageFile, Publish,PublishDate,Date,Deleted FROM shortlist"

InsertCommand="AddProductAndReturnNewProductIDValue"

SelectCommandType="StoredProcedure"

UpdateCommand="UPDATE shortlist SET CategoryID=@.CategoryID,ListTitle=@.ListTitle,Blurb=@.Blurb,ByLine=@.ByLine,HTMLCopy=@.HTMLCopy,MainStory=@.MainStory,Publish=@.Publish,PublishDate=@.PublishDate WHERE Id=@.Id"

Runat="server">

<SelectParameters>

<asp:QueryStringParameter

Name="Id"

QueryStringField="Id"/>

</SelectParameters>

</asp:SqlDataSource>

Is there a section for your InsertParameters, if you've given everything there then it looks like the paramaters just aren't being created.

Test your stored procedure works by calling it from SQL Server Management Studio, i.e.

exec AddListAndReturnNewIDValue
@.EditorId=1,@.CategoryID = 1,@.ListTitle= 'Hello world',@.Blurb = 'This is a test',@.FileName ='testfile.txt',@.ByLine ='Me',@.HTMLCopy = '<html></html>',@.MainStory= 1,
@.MainStoryImageFile ='myfile.txt',@.Publish =0,@.PublishDate = '2007/09/07 12:00:00'

If that works the problem is in your code, and I'd guess it's the Insert parameters. Try creating the SQL Data Source again from scratch.

|||

Thanks for help

No comments:

Post a Comment