i am new to c#. i write a code as below.You see that i obtained columnname and dataType
but How can i get size of field in Table ? Pls help me.

foreach(DataColumn dc in ds.Tables[UpdateTableName].Columns )
lFound = false;
cNewName = dc.ColumnName;
cNewType = dc.DataType.ToString();

Thanks a lot.

Edited 3 Years Ago by happygeek: fixed formatting

Your ds variable looks like it is a DataSet. DataSets normally don't have such things as columnwidths. Use a DataGridView instead.

Thank you for your reply.

You are that MaxLength returns Size . But there is no record in dataset so it returns -1.
pls help me for the same.

MaxLength returns sizes for strings, most others are fixed sizes.

ColName.Length property returns a length of column. i.e.length of column caption.
but i need a length of field used in column. for eg.

I have a field name city. and columnname is colcity. city length is varchar(20)

I need this length(20) from datacolumn object. pls guide me.

Now we are getting somewhere!
If you pose the right questions you will get the answers quicker!
I or someone else will let you know soon, see ya.

here is the sql code to get it

sysobjects.name AS "TABLE_NAME", 
syscolumns.name AS "COLUMN_NAME", 
systypes.name AS "DATA_TYPE", 
syscolumns.LENGTH AS "LENGTH" 
	syscolumns ON sysobjects.id = syscolumns.id 
INNER JOIN                      
	systypes ON syscolumns.xtype = systypes.xtype 
(sysobjects.xtype = 'U') and
sysobjects.name = 'MyTableName'
ORDER BY sysobjects.name, syscolumns.colid

then in your your datacolumn, you will set maxlength to the value returned from the query for length

whew cool!


If we want to run a query then need lenght of columns result . may be column dont in any table but we need lenght of it . please answer to me

This question has already been answered. Start a new discussion instead.