Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Connecting to MySQL with ODBC

Connecting to MySQL with ODBC

Scheduled Pinned Locked Moved Database
databasequestionmysqlxmlhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sps itsec46
    wrote on last edited by
    #1

    Hi guys, I think it's a simple question: I connect to a MySQL database with OdbcDataAdapter and I want to get the schema of the database directly from the database, so I use something like this:

    public DataSet GetData()
    {
    // Create DataSet
    DataSet ds = new DataSet(datasetName);
    OdbcDataAdapter adapter = new OdbcDataAdapter();
    adapter.SelectCommand = GetSelectAllCmd(); // Generates Query: "SELECT * FROM " + tableName
     
    // Get schema from database
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
     
    // Rename table
    adapter.TableMappings.Add("Table", tableName);
     
    // Get data
    adapter.Fill(ds);
     
    // Do we have errors?
    if(ds.HasErrors)
    ds.RejectChanges();
    else
    ds.AcceptChanges();
     
    // Free resources
    adapter.Dispose();
     
    return ds;
    }

    Everything seems working fine, but the schema isn't transfered correctly. The MaxLength property of the DataColumn member has the value of the longest entry in the database. For example if there is a column called 'name' and the database has an entry like 'John' the MaxLength property is 4. But I specified the 'name' column to allow 100 signs while creating the table (... name VARCHAR(100) NOT NULL, ...).   Furthermore I'm not able to change the MaxLength property. The following has no effect:

    ds.Tables[tableName].Columns["name"].MaxLength = 100;

    So I'm not able to insert a name to the 'name' column that is longer than 4. I get the error "The value violates the MaxLength limit of this column". Many thanks in advance!!! Regards, mYkel

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups