Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Basic sql c# question

  • 24-02-2009 11:06am
    #1
    Closed Accounts Posts: 532 ✭✭✭


    I have two tables, one called Users that has a primary column called UserID and another table called Info that has a column with the same name (UserID). The Info->UserID is a foreign key of Users-UserID.

    When I add a new user I want to take the UserID number that is generated automatically for Users-UserID and use it for the Info->UserID. So basically I need to find the highest UserID in the Users table and put it in Info->UserID.

    How can I do this in c#, that is, create and exectue a query that returns me the highest value in Users->UserID?


Comments

  • Registered Users, Registered Users 2 Posts: 2,628 ✭✭✭LowOdour


    Are you using procs?
    OK, in your sql you want to return the new Id
    @IDENTITY) as UserId'
    This returns the new identity created.

    In your c# code, you return the new Id by an ExecuteScalar command and it can be added to a variable for use on the Info table. Thats an overview, should give you the basics to figure out the rest.

    As a side-note, do you need an Info table? For a User (which is unique I pressume), do you want to hold many number of rows of info against him/her? If its just going to be one info record for one user, i would suggest just having the one table!



Advertisement