get value TableAdapter + stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JustRun
    New Member
    • Mar 2008
    • 127

    #1

    get value TableAdapter + stored procedure

    Hi,

    I created a stored procedure that insert values into Table and return the ID "@@IDENTITY AS 'DocumentID' "

    I bind this procedure to my dataset using "FillBy and GetDataBy" How can I retreive the 'DocumentID' value in my Form after I insert the values ?
  • JustRun
    New Member
    • Mar 2008
    • 127

    #2
    ANY IDEAAAAAS PLEAAAAAAAASe

    Comment

    • balame2004
      New Member
      • Mar 2008
      • 142

      #3
      If your procedure returns only @@Identity you can use SqlCommand.Exec uteScalar() to get it. You no need to use dataset to retrieve that single value as dataset consumes space in memory.

      Eg:

      Your SP should be:

      Alter Procedure InsertRec ----

      Insert INTO tableName-----

      select "@@IDENTITY AS 'DocumentID' "



      Sourcecode:

      SqlCommand cmd=new SqlCommand(Conn ectionString);
      cmd.CommandText ="sp_InsertProc ";
      cmd.CommandType = CommandType.Sto redProcedure;
      string insertedRecID=c md.ExecuteScala r().ToString();

      Comment

      Working...