开发者

How would I Select a simple table from sql and display it on a page?

开发者 https://www.devze.com 2023-02-07 21:13 出处:网络
I want to SELECT a user from a table using the WHERE clause.I know how to write the query, but how do I execute it and how do I match the UserId wi开发者_如何学运维th the current one (how do I know wh

I want to SELECT a user from a table using the WHERE clause. I know how to write the query, but how do I execute it and how do I match the UserId wi开发者_如何学运维th the current one (how do I know what the current userid is using the login controls)? I basically want to display profile information by selecting the table and matching it to the userid. Thanks.


The most generic answer i can give, given the lack of information on database, tools etc. Is to learn the rules of ado.net.

http://www.asp101.com/articles/jay/adodotnet/default.asp

this site is a good place to start. The principal is connection, command, then do something with that command( as far as i see it) As Marc has commented, if you are looking at data access there are thousands of options, Linq is a great new way to go however, for more complex situations you may need to mix and match.

To get started with linq i would go to http://msdn.microsoft.com/en-us/library/bb397933.aspx and plough through. However, this may not be what you were asking at all, in which case- sorry.


As simple as possible:

You'll need a method which Opens a Connection to the database, executes a Command on it and then returns some data to a DataReader or Dataset.

Your SQL command is going to be something like:

SELECT * FROM myUserTable Where UserId = x

So your application will need to pass the current user's ID to the database.

I would use a repeater on the front end to display the user information from the table.

Simple example here: http://www.w3schools.com/ASPNET/aspnet_repeater.asp

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消