473,508 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning SCOPE_IDENTITY from SQLDataSource and DetailsView

Howdy,

ASP.Net 2.0 using VB on SQL 2005

This is a two fold issue.

I have a DetailsView control which users can insert or edit items. Editing
works great. Insert works great however I need to display the form once the
user has entered the information and clicked Add.

1) Trying to get the record ID of the inserted record. ReturnValue doesnt
appear to work properly so i'm using an OUTPUT value instead. I get Null
reference errors when working with RETURN SCOPE_IDENTITY()

2) Getting "Procedure or function cp_InsertPublication has too many
arguments specified" error when trying to insert. See code below. All
parameters match up fine.

3) I've tried the following as well, and recieve the same errors:

Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs) Handles
SqlDataSource1.Inserting
Dim para As New System.Data.SqlClient.SqlParameter("returnValue",
TypeCode.Int32, 4, Data.ParameterDirection.ReturnValue)
e.Command.Parameters.Add(para)

End Sub
Thanks!!

David Lozzi
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SMALLConnectionString %>"
DeleteCommand="DELETE FROM [tblPublications] WHERE [ID] = @ID"
InsertCommand="cp_InsertPublication"
InsertCommandType="StoredProcedure"
SelectCommand="SELECT * FROM [tblPublications] WHERE ([ID] =
@ID)"
UpdateCommand="UPDATE [tblPublications] SET [strName] =
@strName, [dtDate] = @dtDate, [strPDF] = @strPDF, [intPages] = @intPages,
[strWrittenBy] = @strWrittenBy, [intType] = @intType, [dtModified] = {fn
Now()} WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="strName" Type="String" />
<asp:Parameter Name="dtDate" Type="DateTime" />
<asp:Parameter Name="intPages" Type="Int32" />
<asp:Parameter Name="strWrittenBy" Type="String" />
<asp:Parameter Name="dtAdded" Type="DateTime" />
<asp:Parameter Name="dtModified" Type="DateTime" />
<asp:Parameter Name="intType" Type="int32" />
<asp:ControlParameter Name="strPDF"
ControlID="dvDetails$Label5" PropertyName="Text" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="PID"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="strName" Type="String" />
<asp:Parameter Name="dtDate" Type="DateTime" />
<asp:Parameter Name="intPages" Type="Int32" />
<asp:Parameter Name="strWrittenBy" Type="String" />
<asp:Parameter Name="intType" Type="int32" />
<asp:Parameter Name="returnValue" Type="int32"
Direction="output" />
</InsertParameters>
</asp:SqlDataSource>

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[cp_InsertPublication]
@strName as varchar(500),
@dtDate as datetime,
@intPages as int,
@strWrittenBy as varchar(50),
@intType as int,
@returnValue as int OUTPUT
AS

INSERT INTO [tblPublications]
([strName], [dtDate], [intPages], [strWrittenBy], [intType], [dtAdded],
[dtModified])
VALUES
(@strName, @dtDate, @intPages, @strWrittenBy, @intType, {fn Now()}, {fn
Now()})

SET @returnValue = SCOPE_IDENTITY()

Mar 29 '07 #1
1 3534
Hi, David,

After posting my post today (Re: Problem with the Legacy ASP files and the
Sql Server Express) and then I saw this post by you, I realize we are
actually haiving the same problem, so do you have any resolution for it yet?
"David Lozzi" <dl****@nospam.nospamwrote in message
news:2F**********************************@microsof t.com...
Howdy,

ASP.Net 2.0 using VB on SQL 2005

This is a two fold issue.

I have a DetailsView control which users can insert or edit items. Editing
works great. Insert works great however I need to display the form once
the
user has entered the information and clicked Add.

1) Trying to get the record ID of the inserted record. ReturnValue doesnt
appear to work properly so i'm using an OUTPUT value instead. I get Null
reference errors when working with RETURN SCOPE_IDENTITY()

2) Getting "Procedure or function cp_InsertPublication has too many
arguments specified" error when trying to insert. See code below. All
parameters match up fine.

3) I've tried the following as well, and recieve the same errors:

Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs) Handles
SqlDataSource1.Inserting
Dim para As New System.Data.SqlClient.SqlParameter("returnValue",
TypeCode.Int32, 4, Data.ParameterDirection.ReturnValue)
e.Command.Parameters.Add(para)

End Sub
Thanks!!

David Lozzi
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SMALLConnectionString %>"
DeleteCommand="DELETE FROM [tblPublications] WHERE [ID] = @ID"
InsertCommand="cp_InsertPublication"
InsertCommandType="StoredProcedure"
SelectCommand="SELECT * FROM [tblPublications] WHERE ([ID] =
@ID)"
UpdateCommand="UPDATE [tblPublications] SET [strName] =
@strName, [dtDate] = @dtDate, [strPDF] = @strPDF, [intPages] = @intPages,
[strWrittenBy] = @strWrittenBy, [intType] = @intType, [dtModified] = {fn
Now()} WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="strName" Type="String" />
<asp:Parameter Name="dtDate" Type="DateTime" />
<asp:Parameter Name="intPages" Type="Int32" />
<asp:Parameter Name="strWrittenBy" Type="String" />
<asp:Parameter Name="dtAdded" Type="DateTime" />
<asp:Parameter Name="dtModified" Type="DateTime" />
<asp:Parameter Name="intType" Type="int32" />
<asp:ControlParameter Name="strPDF"
ControlID="dvDetails$Label5" PropertyName="Text" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="PID"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="strName" Type="String" />
<asp:Parameter Name="dtDate" Type="DateTime" />
<asp:Parameter Name="intPages" Type="Int32" />
<asp:Parameter Name="strWrittenBy" Type="String" />
<asp:Parameter Name="intType" Type="int32" />
<asp:Parameter Name="returnValue" Type="int32"
Direction="output" />
</InsertParameters>
</asp:SqlDataSource>

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[cp_InsertPublication]
@strName as varchar(500),
@dtDate as datetime,
@intPages as int,
@strWrittenBy as varchar(50),
@intType as int,
@returnValue as int OUTPUT
AS

INSERT INTO [tblPublications]
([strName], [dtDate], [intPages], [strWrittenBy], [intType], [dtAdded],
[dtModified])
VALUES
(@strName, @dtDate, @intPages, @strWrittenBy, @intType, {fn Now()}, {fn
Now()})

SET @returnValue = SCOPE_IDENTITY()

Mar 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
18860
by: fuchs.markus | last post by:
Hello, on my page, I have a DetailsViewControl connected to a SqlDataSource. Now when I dynamically set the FilterExpression and FilterParameters - for example in a OnClick-EventHandler of a...
2
1575
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them...
3
6387
by: Jim Andersen | last post by:
Just to let you know, and to help any future sorry sods who gets trapped in the same black hole...... You can't just copy/move a working sql-statement into a stored procedure. Working with a...
3
9232
by: Asaf | last post by:
Hi, I have SqlDataSource control that makes a "select count" to show how many rows there are in a Table and it is working fine on first page load. The problem is that when I am inserting a new...
2
3515
by: YisMan | last post by:
Hi Everybody, I'd Appreciate anybody who can give me a lead here. I'm trying to run an "Insert" command from my ASP page. The command takes as values some on-page textboxes as well some other...
1
4259
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end...
0
987
by: Luke Graham | last post by:
hi, I'm coding a social network style application for my dissertation and am having a few problems, I'm using ASP.net and VB.net I have a button within a DetailsView control that I want to trigger...
1
1797
by: renatois | last post by:
DeleteCommand in SqlDataSource using DetailsView Hi guys, Figure that: - I have two related tables by IDName: 1 - table Name (fields: IDName, Name) 2 - table Products (fields: IDProduct,...
2
5482
by: makennedy | last post by:
Hi Experts, Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere. Basically I have a TreeView Control which I have created...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.