I’m new to asp, so be patient :p
I have an sql database, with a users table that has username and a colour.
My asp master page is reading the current users username and passing it to the content fine.
What I am trying to now do is in the content page grab the colour from the sql table where the username is the current username, and assign it to a string inside the default.aspx.cs file.
How do I do this?
Cheers
EDIT
From your comments, your question is about how to read a value from SQL Server. The most basic way is by just opening a SqlConnection, create a SqlCommand, setting the command text, etc etc. There are many tutorials online. Unfortunately you run the risk of Sql Injection attacks that way.
The best way is to set up an OR Mapper, which creates objects for you, that map directly to your database. The best option there would probably be Entity Framework 4. There are plenty of tutorials online.
END EDIT
Probably the best thing to do would be to set a property in your master page, and then have your default.aspx page read the value from the master page, and do whatever it wants with it.
Having said that, it’s usually a bad idea to be doing database reads from your UI. Usually you’ll want to push that stuff off to another tier, and have your UI focus on just doing UI things.
But, assuming this is just a simple project, then something like the following line should get you where you need to go:
From default.aspx: