Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Thursday, November 28, 2013

How to Make Data Table By C# code in Asp.net Programming:

How to Make Data Table By C# code in Asp.net Programming:

In asp.net Programming, it is very easy that we can create a data table by code and use it as like table.As we know that Table has row and Columns, the sequence is table has number of rows and then Rows has number of columns,In HTML Language we create Table as like This :

       <Table>//Table Open
               //First Row In Table .
        <tr>//Row Open.
                                      //First Column in Row ----------------------------1
                   <td>// Column Open.
                   </td>// Column  Close.
                                    //Second Column In Row…………………………………2
                   <td>// Column Open.
                   </td>// Column  Close.

        </tr>//Row Close.
     </Table>  // Table Close.

Similarly we can add more than one row and more than one column in a table.





Now we  are going to make a Table (dataTable) in asp.net by C# code .As we know the C# provide many library for coding .



Make The object of Data table Class which is present System.data package.

DataTable  dt=new DataTable();
DataTable dt = new DataTable();



//Create Columns……………with data type ……………………..

        DataColumn RegID = new DataColumn("RegID",typeof(Int32));

        DataColumn Marks= new DataColumn("Marks", typeof(Double));

//Add Column into Table …………………………………………



        dt.Columns.Add(RegID);

        dt.Columns.Add(Marks);



//Make the Object of Row………………………………………………………

         DataRow dtRow = dt.NewRow();



//Fill value in to Row ‘s Column……………………………………………………..

       dtRow["RegID"]=1;


       dtRow["Marks"] = 75;



//Add Row in to Table ………………………………………………

dt.Rows.Add(dtRow);

now you have to datatable and then you do fill many controls of asp.net 
as like GridView,Chrats,Lists ETC....

RegID
Marks
1
75

Other Asp.net Related Examples Post: