Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to get a column length from either dataset, datasource, or a row object. What is the syntax for it?

 

Here is the old syntax (ASP):

 

recSet.Fields(iColumnIndex).DefinedSize

 

Thank you

  • 1 month later...
  • *Experts*
Posted
Is the first column a text field? MaxLength only returns the max lenth of text fields, and won't return the max value of number fields.
Posted

You need to get the table schema first before you can be able to get the column length:

 

1. Create your connection

2. Create you Command object(Your SQL-> this will contain the table that you go after), connection)

3. Create your OleDbDataAdapter (or SQLDataAdapter)

4. Create your DataSet

 

5. Your dataAdapter.FillSchema(Your Data Set, System.Data.SchemaType.Mapped);

 

Once you make the FillSchema call, your Maxlength shouldn't return -1 anymore.

 

Hope this will help...

Posted

Here is my code:

 

 

Public Function SelectRows(ByVal query As String) As DataTable

Dim conn As New Data.Odbc.OdbcConnection(dbConnS)

Dim adapter As New Data.Odbc.OdbcDataAdapter

Dim tDataSet As New DataSet

 

Dim tDataTable As New DataTable

 

SelectRows = Nothing

 

adapter.SelectCommand = New Data.Odbc.OdbcCommand(query, conn)

adapter.Fill(tDataSet, System.Data.SchemaType.Mapped)

tDataTable = tDataSet.Tables(0)

Dim etest As Integer

For etest = 0 To tDataTable.Columns.Count - 1

MsgBox(tDataTable.Columns(etest).MaxLength.ToString, , tDataTable.Columns(etest).ToString)

Next

 

SelectRows = tDataTable

 

 

 

conn.Dispose()

adapter.Dispose()

tDataSet.Dispose()

 

 

 

It returns -1 as maxlen for every field. I added "System.Data.SchemaType.Mapped" to the fill command and still no avail.

www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...