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 all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back a page or two to re-sync the thread and this will then show latest posts. Thanks, Mike.

Basic sql c# question

  • 24-02-2009 12:06pm
    #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,587 ✭✭✭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