Solved

MySQLDataAdapter doesn't set AutoIncrement property in Datatable

Posted on 2015-02-18
2
139 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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