Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Inserting a record and retrieving recordid

Inserting a record and retrieving recordid

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadminhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moazzamahmed
    wrote on last edited by
    #1

    hi all, Im using Microsoft Data Application Block for this. Im trying to execute a sql procedure that inserts a row. I need to get the identity field (eventID) returned back to me. Ive tried several ways but it wont work. Anyone have a complete example written in c# 1.0 for sql server 8.0, with c# code and stored procedure? Really appreciate all the help. thanks Moazzam

    C M 2 Replies Last reply
    0
    • M moazzamahmed

      hi all, Im using Microsoft Data Application Block for this. Im trying to execute a sql procedure that inserts a row. I need to get the identity field (eventID) returned back to me. Ive tried several ways but it wont work. Anyone have a complete example written in c# 1.0 for sql server 8.0, with c# code and stored procedure? Really appreciate all the help. thanks Moazzam

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Why don't you show us your code and we can show you where to put it right? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

      1 Reply Last reply
      0
      • M moazzamahmed

        hi all, Im using Microsoft Data Application Block for this. Im trying to execute a sql procedure that inserts a row. I need to get the identity field (eventID) returned back to me. Ive tried several ways but it wont work. Anyone have a complete example written in c# 1.0 for sql server 8.0, with c# code and stored procedure? Really appreciate all the help. thanks Moazzam

        M Offline
        M Offline
        malharone
        wrote on last edited by
        #3

        Assuming your table contains an Identity column .. create procedure EmployeeCreate (@name varchar(20), @dept varchar(20), @employeeid numeric out) as begin insert into Emplyee (Name, Department) values (@name, @dept) select @employeeid = @@identity end So when you execute your SQL command from .net and pass parameters, pass a parameter for "@employeeid". You wont need to set a value for this SqlParameter, but you'll have to set the correct Direction. - Malhar

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups