[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Diehsner

8/9/2002 10:38:00 AM

Hi,

I have a Select-Statement ( "Select * from Customers" ).
The execution works fine ( ODBCConnection, ODBCCommand, ODBCDataReader ).
I get all Data, but not the size of the fields.
MyReader.GetName(), MyReader.GetString(), MyReader.GetDataTypeName()

How can I get an information, that field "A" is varchar (20) and not only
varchar?

Gero



3 Answers

Bob Beauchemin

8/9/2002 6:27:00 PM

0

Three ways.

The OdbcDataReader has a method called GetSchemaTable, returns a DataTable.
You can use this DataTable to get ColumnLength for each column, if supported
by the underlying ODBC driver.

If you use MissingSchemaAction = MissingSchemaAction.AddWithKey on your
DataAdapter, DataAdapter.Fill will populate that MaxLength column. Bear in
mind that the DataSet is based on .NET types rather than database types, so
you won't see Varchar anywhere in the DataSet's metadata. Most data
providers' type mappings are doc'd.

You can also use DataAdapter.GetSchema, which will populate MaxLength as
well.

Bob Beauchemin
http://staff.develo...



"Diehsner" <g.diehsner@gbo-ag.de> wrote in message
news:#hZRBA4PCHA.2660@tkmsftngp08...
> Hi,
>
> I have a Select-Statement ( "Select * from Customers" ).
> The execution works fine ( ODBCConnection, ODBCCommand, ODBCDataReader ).
> I get all Data, but not the size of the fields.
> MyReader.GetName(), MyReader.GetString(), MyReader.GetDataTypeName()
>
> How can I get an information, that field "A" is varchar (20) and not only
> varchar?
>
> Gero
>
>
>


Diehsner

8/12/2002 11:43:00 AM

0

First Way:
The ODBCDataReader has no ColumnLength-Property! I get it on friday from
Microsoft-Download-Page! MaxLength shows for SQLServer2000 -1 for
all columns. DataTable don't have a property ColumnLength!
( Framework-Version 1.0.3705 ).

SecondWay:
.Net types are OK, if I have the length of the strings. The first test seem
to work.

Thanks
Gero Diehsner


"Bob Beauchemin" <no_bobb_spam@develop.com> schrieb im Newsbeitrag
news:OHYqVG8PCHA.2292@tkmsftngp10...
> Three ways.
>
> The OdbcDataReader has a method called GetSchemaTable, returns a
DataTable.
> You can use this DataTable to get ColumnLength for each column, if
supported
> by the underlying ODBC driver.
>
> If you use MissingSchemaAction = MissingSchemaAction.AddWithKey on your
> DataAdapter, DataAdapter.Fill will populate that MaxLength column. Bear in
> mind that the DataSet is based on .NET types rather than database types,
so
> you won't see Varchar anywhere in the DataSet's metadata. Most data
> providers' type mappings are doc'd.
>
> You can also use DataAdapter.GetSchema, which will populate MaxLength as
> well.
>
> Bob Beauchemin
> http://staff.develo...
>
>
>
> "Diehsner" <g.diehsner@gbo-ag.de> wrote in message
> news:#hZRBA4PCHA.2660@tkmsftngp08...
> > Hi,
> >
> > I have a Select-Statement ( "Select * from Customers" ).
> > The execution works fine ( ODBCConnection, ODBCCommand,
ODBCDataReader ).
> > I get all Data, but not the size of the fields.
> > MyReader.GetName(), MyReader.GetString(), MyReader.GetDataTypeName()
> >
> > How can I get an information, that field "A" is varchar (20) and not
only
> > varchar?
> >
> > Gero
> >
> >
> >
>
>


Bob Beauchemin

8/12/2002 11:15:00 PM

0

ColumnLength is not a property of the OdbcDataReader.
OdbcDataReader.GetSchemaTable() returns a System.Data.DataTable containing
metadata about the DataReader's columns. One of the columns in the DataTable
returned by GetSchemaTable is "ColumnLength". There is one row in the schema
table for each column in the resultset.

Hope this helps,
Bob Beauchemin
http://staff.develo...


"Diehsner" <g.diehsner@gbo-ag.de> wrote in message
news:Ok1#TSeQCHA.780@tkmsftngp12...
> First Way:
> The ODBCDataReader has no ColumnLength-Property! I get it on friday from
> Microsoft-Download-Page! MaxLength shows for SQLServer2000 -1 for
> all columns. DataTable don't have a property ColumnLength!
> ( Framework-Version 1.0.3705 ).
>
> SecondWay:
> .Net types are OK, if I have the length of the strings. The first test
seem
> to work.
>
> Thanks
> Gero Diehsner
>
>
> "Bob Beauchemin" <no_bobb_spam@develop.com> schrieb im Newsbeitrag
> news:OHYqVG8PCHA.2292@tkmsftngp10...
> > Three ways.
> >
> > The OdbcDataReader has a method called GetSchemaTable, returns a
> DataTable.
> > You can use this DataTable to get ColumnLength for each column, if
> supported
> > by the underlying ODBC driver.
> >
> > If you use MissingSchemaAction = MissingSchemaAction.AddWithKey on your
> > DataAdapter, DataAdapter.Fill will populate that MaxLength column. Bear
in
> > mind that the DataSet is based on .NET types rather than database types,
> so
> > you won't see Varchar anywhere in the DataSet's metadata. Most data
> > providers' type mappings are doc'd.
> >
> > You can also use DataAdapter.GetSchema, which will populate MaxLength as
> > well.
> >
> > Bob Beauchemin
> > http://staff.develo...
> >
> >
> >
> > "Diehsner" <g.diehsner@gbo-ag.de> wrote in message
> > news:#hZRBA4PCHA.2660@tkmsftngp08...
> > > Hi,
> > >
> > > I have a Select-Statement ( "Select * from Customers" ).
> > > The execution works fine ( ODBCConnection, ODBCCommand,
> ODBCDataReader ).
> > > I get all Data, but not the size of the fields.
> > > MyReader.GetName(), MyReader.GetString(), MyReader.GetDataTypeName()
> > >
> > > How can I get an information, that field "A" is varchar (20) and not
> only
> > > varchar?
> > >
> > > Gero
> > >
> > >
> > >
> >
> >
>
>