Bug #36362 Cannot get Maxlength from Column after DataAdapter.Fill method
Submitted: 27 Apr 2008 8:32 Modified: 29 Apr 2008 13:53
Reporter: Anson Chapman Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.2 Connector/Net OS:Windows (XP - SP2)
Assigned to: CPU Architecture:Any
Tags: dataadapter, dataset, DataTable

[27 Apr 2008 8:32] Anson Chapman
Description:
When doing a fill adapter in VB 2008 with connector/Net 5.2 (see routine below)

Without the FillSchema i cannot get the maxlenght set properly in the column attributes of the datatable for string etc.. Populating unknown MySQL tables is needed for certain types of operations. Note: this creates another problem which will be placed in a another bug report.

Public Function GetDGData(ByVal sDB As String, ByVal selectCommand As String) As DataTable

        Try
          Call ClearErrors("Get DG Data")
          ' Create a connection string
          If sDB = "GENSYS" Then
            Call MyConnectString("GENSYS", True)
          Else
            Call MyConnectString(gGeneral.DataDB, True)
          End If
          ' Create a new data adapter based on the specified query.
          MyDGdaAdapter = New MySqlDataAdapter(selectCommand, MyDGConnString)
          ' Create a command builder to generate SQL update, insert, and
          ' delete commands based on selectCommand. These are used to
          ' update the database.
          MyDGCmdBuilder = New MySqlCommandBuilder(MyDGdaAdapter)
          ' Populate a new data table and bind it to the BindingSource.
          MyDGdtDataTable = New DataTable()
          MyDGDataset = New DataSet()
          MyDGdaAdapter.FillSchema(MyDGDataset, SchemaType.Mapped)
          ' Without above statement cannot get proper length for string fields
          MyDGdaAdapter.Fill(MyDGDataset)
          Return (MyDGDataset.Tables(0))
        Catch eX As MySqlException
          Call SetMySQLErrors(eX, "Get Data - MySql-DataGridView")
        End Try
        Return (Nothing)

How to repeat:
See above function in description

Suggested fix:
Automatically fill in all schema attribules especially field sizes
[29 Apr 2008 13:53] Reggie Burnett
This is not a bug.  The data adapter in this case will only call MySqlDataReader.GetSchemaTable when FillSchema is called otherwise it just jams the data into the table.  This makes sense.  Most of the time you just care about the data and, when you do care about the schema, you just call FillSchema.