Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to retrieve the column datatype size form the data table.

thanks in advance :)

What I have tried:

Dim tblProducts as DataTable
.
.
.

For i As Integer = 0 To tblProducts.Rows.Count
                     Dim d = tblProducts.Columns(i).DataType ' here How to retrieve the datatype size ?? :(
        Next
Posted
Updated 9-Jan-18 6:45am
v2

To retrieve the size of a string column, use the MaxLength[^] property:
VB.NET
Dim s As Integer = tblProducts.Columns(i).MaxLength
 
Share this answer
 
Do you mean the data type for column 'size'?
VB
tblProducts.Columns["size"].DataType

Also! Columns is a collection of the columns (surprisingly) and has nothing to do with the number of rows!!!
If you want to iterate over the columns use a loop like this:
VB
For Each column In tblProducts.Columns
  ' Your code here
Next
 
Share this answer
 
Comments
ketan Ram Patil 8-Jan-18 4:18am    
thanks for your valuable replay. :)

But i want to know the size of each column Data type.

eg.if column Product contain string data type then how to retrive the actual size of string data type.


i want to create a new table from the datatable.

so to create a new table i am able to retrieve the column name and data type but not able retrieve actual datatype size :( ????????
Kornfeld Eliyahu Peter 8-Jan-18 4:39am    
Do you mean if in the SQL you declared CHAR(30) than you want to get 'String' and '30'?
You can not! DataTable is a generic type to work with any kind of data source and works on the minimal level...
But - to contradict that general nature - for text (string variant) types there is a MaxLength value, however... not all provides will set that value, so you may not build on it. You also have to get the schema info when filling the data...
Adapter.Fill(...);
Adapter.FillSchema(...);

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