Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to get Values from Database to list in Asp.Net and C#(DataLayer)
Posted

 
Share this answer
 
You should use a SqlConnection and set its ConnectionString property to connect to SQL Server DB. Then you should create a SqlCommand object and set its Connection property with your SqlConnection and CommandText property to a Sql command(e.g. Select * from MyTable). There are many ways to fetch data from SqlCommand, but the simplest way is using SqlDataReader. In this way you should use ExecuteReader() method of SqlCommand to load fetched data from database into your SqlDataReader. It's done. Now you should assign SqlDataReader to your DataGrid control's DataSource property and call DataBind() method.
 
Share this answer
 
Comments
MAGuru 17-Jun-14 8:17am    
How to get values through generic list

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900