Solved

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

Posted on 2010-11-18
6
904 Views
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 

oAdapter.Fill(oDataTable)



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) 



oDataTable.AcceptChanges()



End Sub

Open in new window

0
Comment
Question by:ou81aswell
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Calling the AcceptChanges does not save changes to the database. Check this example

http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c13041
0
 

Author Comment

by:ou81aswell
Comment Utility
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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
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

dataadapter.Update(tablename)
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:ou81aswell
Comment Utility
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.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
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)

oAdapter.UpdateAll()
0
 

Author Comment

by:ou81aswell
Comment Utility
The CommandBuilder worked but the OdbcDataAdapter doesn't have an UpdateAll method so I used  oAdapter.Update(oDataTable).
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

10 Experts available now in Live!

Get 1:1 Help Now