Trouble binding C1FlexGrid to MySQL ODBC Driver - reads but won't update

Posted on 2010-11-18
Last Modified: 2012-05-10
I can't figure out how to get my C1 FlexGrid (2.6) to update table data in the underlying database connected via an ODBC DSN.

The grid displays the data as expected and allows me to change it but when I reopen the program, the changes are gone. I use the same ODBC DSN in other apps (VB6 with a good old vsFlexGrid) and can update the data there.

I'm using version 5.1 of the MySQL ODBC driver on a Win 7 x64 machine and VS 2010 / Visual Basic

I can't get this simple windows form application with a C1FlexGrid bound to a DataTable to update the database.

Any tips as to what I am doing wrong would be appreciated.

Here's the relevant code:

'Grid is a control on the form of type C1.Win.C1FlexGrid

Private oConnOdbc As OdbcConnection = New OdbcConnection("Provider=MSDASQL;DSN=IA CRM")

Private Sub Form1_Load...

Dim oAdapter As New OdbcDataAdapter() 
oAdapter.SelectCommand = New OdbcCommand("Select * From Testing", oConnOdbc) 

Dim oDataTable As New DataTable 

Grid.DataSource = oDataTable

End Sub 

Private Sub Form1_FormClosing... 

' from what I have read, this shouldn't be necessary
Dim oDataTable As DataTable = CType(Grid.DataSource, DataTable) 


End Sub

Open in new window

Question by:ou81aswell
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
  • 3
  • 3
LVL 83

Expert Comment

ID: 34164967
Calling the AcceptChanges does not save changes to the database. Check this example

Author Comment

ID: 34165407
Thanks but that's for the DataGridView although I'm sure it's similar to the C1FlexGrid (from Component One) in the way that it interacts with the database.

I was hoping to avoid having to write a hundred lines of code in order to get the simplest of simplest grid based editors to work.
LVL 83

Expert Comment

ID: 34165515
You dont have to write a lot of code. All you have to do is supply the Select command, then you can use the CommandBuilder to automatically produce the Insert, Update, and Delete commands for you. Then when you want to commit changes to the db, it only takes a function call

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.


Author Comment

ID: 34165713
I'm not familiar with the command builder. I will look into it. Thanks.

I guess my problem is that I'm going by examples (provided by Component One) that simply setup a DataTable and assign it to the grid's datasource property. They make no mention of data adapters or readers even though the examples are in VB.NET. Perhaps I'm looking at the wrong examples. I'm coming from ADO in VB6 land with the good old MS/VS FlexGrid ActiveX and so I'm extra confused!

I guess I need to study the code in the first link you sent but it's frustrating having spent so much time on the most trivial task. I was hoping someone could suggest what needs to be added to my code because I've been chasing my tail looking at all sorts of examples like this which led me to post my question here.
LVL 83

Accepted Solution

CodeCruiser earned 500 total points
ID: 34165870
You can try by changing this code

Dim oAdapter As New OdbcDataAdapter()
oAdapter.SelectCommand = New OdbcCommand("Select * From Testing", oConnOdbc)

to this

Dim oAdapter As New OdbcDataAdapter()
oAdapter.SelectCommand = New OdbcCommand("Select * From Testing", oConnOdbc)
Dim builder as New ODBCCommandBuilder(oAdapter) 'This is all you need to generate the commands.

Then on a button click (save button)


Author Comment

ID: 34170563
The CommandBuilder worked but the OdbcDataAdapter doesn't have an UpdateAll method so I used  oAdapter.Update(oDataTable).

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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