C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Creating the datatable and binding it to datagrid


Posted Date: 06 Mar 2004    Resource Type: Articles    Category: .NET Framework
Author: MUNIKUMAR RMember Level: Silver    
Rating: Points: 10



Creating a datatable and binding it to datagrid:
First DataTable is created,then columns are added to table and finally rows are added to the table.

//Creates a new datatable named “Details” and dataset

DataTable objDataTable=new DataTable("Details");
DataSet objDataSet=new DataSet();

//Adding "Details" table to the dataset.

objDataSet.Tables.Add(objDataTable);


/*Following code adds the columns “Name”,”Address”,”City”,”Pin” and its datatypes to the created data table.*/

objDataTable.Columns.Add("Name",typeof(string));
objDataTable.Columns.Add("Address",typeof(string));
objDataTable.Columns.Add("City",typeof(string));
objDataTable.Columns.Add("Pin",typeof(Int32));

//Creates a new datarow for the table objDataTable

DataRow objDR=objDataTable.NewRow();
//The following code adds the data to the table.
objDR ["Name"]="X";
objDR ["Address"]="Thiruvanmiyur";
objDR ["City"]="Chennai";
objDR [“Pin”]=600040;

//Adding the created data row to the datatable

objDataTable.Rows.Add(objDR);


//The following code binds “Details” table present in DataSet to DataGrid
DataGrid1.SetDataBinding(objDataSet,”Details”);






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Making the datagrid non editable
Previous Resource: Adding your own tablestyle to datagrid depending on the DataTable
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use