Solved

MySQLDataAdapter doesn't set AutoIncrement property in Datatable

Posted on 2015-02-18
2
132 Views
Last Modified: 2015-03-05
Hi Experts,

I have a MySql table with a column set to AutoIncrement=True and NotNull=True.  Type is Int(10) Unsigned.  My Application needs to add records to an in-memory datatable and them use the adapter to save the changes.

When I create a MySQLDataAdapter and fill my table it is supposed to set the DataColumn.AutoIncrement to true after reading the schema from the database.  It is not.  I tried many ways to fill the data and none of them are working.

Public Adapter As MySqlDataAdapter
Adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
Adapter.Fill(MyDataSet, "MyTable")

Open in new window

I also tried
Public Adapter As MySqlDataAdapter
Adapter.FillSchema(MyDataSet, SchemaType.Source, "MyTable")
Adapter.Fill(MyDataSet, "MyTable")

Open in new window

as well as SchemaType.Mapped.

In every case my Datacolumn.Autoincrement=False.
Is there something I am doing wrong?
I am using MySQL 5.5.39-MariaDB and VB.NET 4.0

Now I could work around this by not using the autoincrement and using a GUID as a primary key instead, but I'd like to try the "normal" way of working with the table.
0
Comment
Question by:MasterWoodsman
2 Comments
 
LVL 14

Accepted Solution

by:
Lokesh B R earned 500 total points
ID: 40639557
Hi,

I think You need to set the AutoIncrement properties manually.

Change the following
Adapter.MissingSchemaAction = MissingSchemaAction.Add;

http://www.pcreview.co.uk/threads/datatable-autoincrement-problem.1247578/
0
 
LVL 1

Author Comment

by:MasterWoodsman
ID: 40647763
That Worked!  I had to make sure that I loaded the schema without data before manually setting the column's autoincrement property, and then actually load the data.

My full code is
Public Adapter As MySqlDataAdapter
Adapter.FillSchema(MyDataSet, SchemaType.Source, "MyTable")
Adapter.MissingSchemaAction = MissingSchemaAction.Add
dim dc as DataColumn = ds.Tables("MyTable").Columns("ColumnWithAutoIncrement")
dc.AutoIncrement = True
Adapter.Fill(MyDataSet, "MyTable")

Open in new window


Thanks for the help!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Creating and Managing Databases with phpMyAdmin in cPanel.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now