.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How To Bind Data In Datagrid From Database?

Posted By:Ghanashyam Nayak       Posted Date: September 09, 2010    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

Depending On Your Arguments It Will Bind That Table Data Into DataGrid...

01.//     1st Argument : For Which Datagrid You Want Bind Data...
02.//     2nd Argument : Which Table's Data You Want To Bind In Given Datagrid...
04.private void BindData(DataGrid DataGrid1, String TableName)
06.      OleDbConnection ocon=newOleDbConnection(ConfigurationSettings.AppSettings["<>"]);
07.      OleDbCommand ocmd=new OleDbCommand();
08.      ocmd.CommandText="SELECT * FROM TableName";
09.      ocmd.Connection=ocon;
10.      ocmd.Connection.Open();
11.      OleDbDataReader odr=ocmd.ExecuteReader();
12.      DataGrid1.DataSource=odr;
13.      DataGrid1.DataBind();
14.      ocmd.Connection.Close();


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend