c# - How do I assign a sql record value to string in asp.net -


I'm new to esp, so be patient: p

I have a SQL database User table with user name and one color.

My ASP Master page is reading the current user username and sending it to the content properly. Now what I'm trying to do is take the color from the SQL table in the content page, where the user name The current username is, and specify it in a string within the default .aspx.cs file.

How do I do this?

Cheers

edit

With your comments, how does your question read the value from SQL Server? The most fundamental way is to open an SqlConnection, create a SqlCommand, command text set, etc. Too many tutorials are online Unfortunately, you run the risk of SQL injection attacks in this way.

The best way to set one or mapper, which creates an object for you, it maps to your database directly. The best option is probably the Entity Framework. There are so many tutorials online.

Edit END

Perhaps the best part is to set up a property in your master page, and then your default. ASPX page master page After reading this, it usually is a bad idea to read the database from your UI. Normally you want to take that stuff to another level, and UI is your UI focus on doing things.

But assuming this is just a simple project, then you need something like the following line, where you should go:

By default. Aspx:

  String value = (this.Master YourMasterPageClass) .YourProperty;    

Comments