field properties aren't there

R

rodchar

hey all,
I'm doing the following:
SqlCommand mycmd = new SqlCommand(sqlText, conn);
SqlDataAdapter da = new SqlDataAdapter(mycmd);
DataTable tbl = new DataTable();
da.Fill(tbl);

Well, when I check tbl.Columns[x].MaxLength all columns show -1. I checked
and there are columns and I can do tbl.Columns[x].ColumnName. Can someone
please explain?

thanks,
rodchar
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Explain what?

From MSDN:
The maximum length of the column in characters. If the column has no maximum
length, the value is -1 (default).


What were you expecting?
 
R

rodchar

Actually, in the database, the field does have a length specified.

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Explain what?

From MSDN:
The maximum length of the column in characters. If the column has no maximum
length, the value is -1 (default).


What were you expecting?

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
rodchar said:
hey all,
I'm doing the following:
SqlCommand mycmd = new SqlCommand(sqlText, conn);
SqlDataAdapter da = new SqlDataAdapter(mycmd);
DataTable tbl = new DataTable();
da.Fill(tbl);

Well, when I check tbl.Columns[x].MaxLength all columns show -1. I checked
and there are columns and I can do tbl.Columns[x].ColumnName. Can someone
please explain?

thanks,
rodchar
 
L

Lasse Vågsæther Karlsen

rodchar said:
Actually, in the database, the field does have a length specified.

Perhaps the database provider code doesn't read those values?
Did you check if the columns/rows contains any data?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


rodchar said:
Actually, in the database, the field does have a length specified.

It might have, but the returned type is string which has no type. I checked
it on a CHAR(10) column and it did return String and MaxLength was -1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top