Click here to Skip to main content
15,886,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am New to Programming and I want to know About How to Create user defined Data Table In ASP.Net.2010


Please help me with the Same.
Posted
Comments
Sravanthid28 18-Sep-12 7:27am    
HI u want to create dynamic table or user defined table?
zaid Qureshi 18-Sep-12 7:35am    
user defined table

1 solution

If I understood well you want to create a DataTable programmatically:

This is a way to achieve that:

C#
DataTable dt = new DataTable();

DataColumn column = new DataColumn();
column.ColumnName = "ID";
column.AllowDBNull = false;
column.DataType = typeof(int);
column.AutoIncrement = true;
column.AutoIncrementSeed = 1000;
column.AutoIncrementStep = 1;

dt.Columns.Add(column);
dt.Columns.Add("Name", typeof(string));
dt.PrimaryKey = new DataColumn[] { column };

DataRow row = dt.NewRow();
row["Name"] = "Mario";
dt.Rows.Add(row);


Cheers
 
Share this answer
 
v2
Comments
zaid Qureshi 18-Sep-12 7:53am    
dear Mario Majcica i am new to programmming so tell me how to create the table.
Normally as we do...
Mario Majčica 18-Sep-12 7:55am    
You need to be more explicit. What kind of table you are trying to create? What for? Where?
zaid Qureshi 18-Sep-12 8:43am    
for the database Purpose i want to create table and want to define the Keys(primary key etc)
Mario Majčica 18-Sep-12 8:46am    
So you are trying to create tables in database and then use them in your code? Here Entity Framework comes in handy. Check this video: http://msdn.microsoft.com/en-us/data/gg702906
and
http://msdn.microsoft.com/en-us/data/cc546554
On this page you will find many interesting videos:
http://msdn.microsoft.com/en-us/data/videos.aspx

Cheers
zaid Qureshi 18-Sep-12 9:16am    
oh thanks a lot....God Bless...!!!

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