Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8360009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:19:46+00:00 2026-06-09T11:19:46+00:00

I have a strongly-typed dataset that is using DBDirectMethods to insert data into a

  • 0

I have a strongly-typed dataset that is using DBDirectMethods to insert data into a database using calls to stored procedures. The stored procedures return the primary key of the newly-created record. Here’s a sample stored procedure:

CREATE PROCEDURE dbo.CreateUser
(
    @UserName   VARCHAR(50)
    @Password   VARCHAR(50)
)
AS

SET NOCOUNT OFF

DECLARE @UserID INT

BEGIN TRANSACTION

INSERT INTO dbo.Users (UserName, Password) VALUES (@UserName, @Password)

SET @UserID = SCOPE_IDENTITY()

INSERT INTO dbo.Users_History (UserID, Status, TimeStamp) VALUES (@UserID, 'C', GETUTCDATE())

COMMIT TRANSACTION

RETURN @UserID

GO

If I execute the stored procedure from SSMS, then the user account is created, the history table updated, and the primary key returned. If I run my application using the strongly-typed dataset and have SQL Profiler ticking away, I can see the same code being executed; however, the dataset returns -1 as the primary key and breaks the app.

Inside the VS-generated code for the table adapter, the relevant lines are:

this._adapter.InsertCommand.CommandText = "dbo.CreateUser";
this._adapter.InsertCommand.CommandType = global::System.Data.CommandType.StoredProcedure;
this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@UserName", global::System.Data.SqlDbType.VarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, "UserName", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Password", global::System.Data.SqlDbType.VarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, "Password", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));

and

try {
    int returnValue = this.Adapter.InsertCommand.ExecuteNonQuery();
    return returnValue;
}
finally {
    if ((previousConnectionState == global::System.Data.ConnectionState.Closed)) {
        this.Adapter.InsertCommand.Connection.Close();
    }
}

which is all just the standard boiler-plate code that VS usually generates – nothing has been edited by hand. It just doesn’t pick up the return value.

I am running Windows 7 with SQL 2008 R2 SP1 Express.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:19:49+00:00Added an answer on June 9, 2026 at 11:19 am

    From memory, the issue here is that the value ExecuteNonQuery() returns is the number of rows affected by the query.

    Instead, your return value should be accessible via:

    InsertCommand.Parameters["@RETURN_VALUE"].Value;
    

    or

    InsertCommand.Parameters[0].Value;
    

    In addition, you can try changing your return parameter name to @UserID rather than @RETURN_VALUE but it should still work as you have it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using strongly typed dataset and have many tables in that.. The problem
I'm using System.Data.Design.TypedDataSetGenerator to convert a .xsd file (generated by VS2008) into a strongly-typed
I have a winforms app that uses a strongly typed custom DataSet for holding
I've got a bunch of strongly typed DataSet that each have two tables. One
I have a strongly-typed DataTable returned in a strongly-typed DataSet from a database query.
Background information first: We are using a strongly-typed DataSet to manage transaction files. That
I have a strongly-typed dataset (VB.NET), using .NET Framework 2.0. Given a DataRow in
I have a strongly typed DataTable created with the VS2005/VS2008 DataSet designer. The table
i have an strongly typed object that represents all of the textbox properties of
I'm wanting to have a strongly typed user control that accepts the class PaginatedList<T>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.