Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQLDataAdapter doesn't set AutoIncrement property in Datatable

Posted on 2015-02-18
2
Medium Priority
?
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Lokesh B R earned 2000 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

705 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