0

Hi,
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 by happygeek: fixed formatting

6
Contributors
12
Replies
13
Views
8 Years
Discussion Span
Last Post by mostnour
Featured Replies
  • here is the sql code to get it [code] SELECT sysobjects.name AS "TABLE_NAME", syscolumns.name AS "COLUMN_NAME", systypes.name AS "DATA_TYPE", syscolumns.LENGTH AS "LENGTH" FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id INNER JOIN systypes ON syscolumns.xtype = systypes.xtype WHERE (sysobjects.xtype = 'U') and sysobjects.name = 'MyTableName' ORDER BY sysobjects.name, syscolumns.colid … Read More

0

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

0

First,
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.

0

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.

0

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.

1

here is the sql code to get it

SELECT
sysobjects.name AS "TABLE_NAME", 
syscolumns.name AS "COLUMN_NAME", 
systypes.name AS "DATA_TYPE", 
syscolumns.LENGTH AS "LENGTH" 
FROM         
	sysobjects 
INNER JOIN 
	syscolumns ON sysobjects.id = syscolumns.id 
INNER JOIN                      
	systypes ON syscolumns.xtype = systypes.xtype 
WHERE     
(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

Votes + Comments
whew cool!
0

Hi

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.