Hey guys,

I am developing a web based database for a company for my year work placement from university. I was wondering if anyone knew a way of retrieving the user ID from the database through the web page? Each table in the SQL Server database has an automatic Identity column which will be used for searching and retrieving customer information. I need to find away of retrieving this ID to give to the customer for searching. Any ideas????

(sorry if this thread should be in SQL forum instead)

Thanks, any ideas greatly appreciated!


If you use authentication, it is possible to retrieve user id from the database. You will run simple select query against the database like this : select userid from users where username=@username (provided that the username is unique for each user). Tell me the details and i will expand this for you.

Basically I want to be able to search for customer details etc. I have used a Customer ID number as the Primary key, I wish to use this PK as a customer number to search by. Yes the customer names will probably unique but as I am working with different companies the company name (customer name) may change so cannot use this as a PK. Is there a way of retreiving this ID number to give to the customers so it can be used as a reference number/customer number and is there a way of also searching by the name if the customer does not remember there number??

It is basic database operation. Create a TableAdapter, specify a select query, execute the query against the database, and set it to a GridView's datasource, and bind the GridView. Do you want a step by step explanation?

You will most likely want the customer to login, right? Once the customer logs in, store their userid within a session variable or a cookie. This way the user logs in and just clicks links to get info and never has to enter in any data.

To set the session, just do a select from the database and set the value you retrieve as the session:

Session("UserID") = commandname.ExecuteScalar()

Then everytime you need information, just do a substitution for the parameter:

commandname.Parameters.AddWithValue( "@UserID", Session("UserID").ToString() )