473,378 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problems with Update and MySqlDataAdapter

Hi,

I've been using MSSQL2k as the DB for several years now and I have a few
apps where I do some changings in the dataset and need to update the
underlying db and that I do with the sqlcommandbuilder object and the
sqldataadapter.

I have a sqlconnection object, a sqldatadapter object and a dataset filled
with data from the dataadapter. Then I iterate trhough the dataset updating
some values and at last I update the db. For this to success you must have a
primary key in the datadapter (table)

Now I'm trying to do the same with MySql 4.1.10b db and Connector.net and am
getting error message saying

*******************************************
Connection must be valid and open
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Connection must be
valid and open

Source Error:
Line 634: 'Update dataset & grid w new values
Line 635: daBuilder = New MySqlCommandBuilder(daRes)
Line 636: daRes.Update(dsRes, "Result")
Line 637: grid.DataSource = dsRes
Line 638: grid.DataBind()
********************************************

It stops on line 636 with this error message, works very good with exactly
the same code but sql objects with sqlerv2k

Any ideas?

TIA

Kenneth P
Nov 19 '05 #1
3 1404
Kenneth, I do not see the code where you are opening your connections
but this code can check to see if it is open and if it is not, it will
open it for you:
if(yourConnection.State != ConnectionState.Open)
{
yourConnection.Open();
}

Jason Bentley
http://geekswithblogs.net/jbentley

Nov 19 '05 #2
Hi Jason,

I'm 100% sure all connections are closed when I try to update the db, but it
has been no problem with sqlserv2k for three years now, why is it a problem
with mysql?

I've added some code to open the connection with three lines, then the old
code that worked quite well and then closing the connection again.

conStrDiskoweb = ConfigurationSettings.AppSettings("conStrDiskoweb" )
connDiskoweb = New MySqlConnection(conStrDiskoweb)
connDiskoweb.Open()

daBuilder = New MySqlCommandBuilder(daRes)
daRes.Update(dsRes, "Result")
grid.DataSource = dsRes
grid.DataBind()

connDiskoweb.Close()

I still get the exactly same eroor message.

Kenneth

"Jason Bentley" wrote:
Kenneth, I do not see the code where you are opening your connections
but this code can check to see if it is open and if it is not, it will
open it for you:
if(yourConnection.State != ConnectionState.Open)
{
yourConnection.Open();
}

Jason Bentley
http://geekswithblogs.net/jbentley

Nov 19 '05 #3
Hmmm, I dunno. In theory, OleDb and SqlClient should function the same.
Jason Bentley
http://geekswithblogs.net/jbentley

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: zhaoJian | last post by:
Here it is my code ,but it can't update the database.How to do it ? In _UpdateUnit event, I can not get the original value to @Original_UnitID,so I set a hidden column named LabelKey.But It...
5
by: PKin via DotNetMonster.com | last post by:
Hi, I am trying to retreive a record from a MySql table and I get this error telling : Unable to convert MySQL date/time value to System.DateTime I am user the following command:...
12
by: TB | last post by:
Hi All: I am trying to create a variation on the standard datagrid, whereby the datagrid is only shown after pressing some buttons. This reason for this is that I would like to use the same...
9
by: Geraldine Hobley | last post by:
Hello I'm getting the above mentioned error in my applicatio I have a datagrid bound to a datasource like s MyDatagrid.DataSource = Mydataset.Tables(Order) - this all works fine However I...
8
by: NetRacer | last post by:
hi, i have a DataGrid with a DataView as source. the data is read correctly from the db and shown on screen. the problem appears, when i want to add some rows to the grid. first it adds them...
4
by: TB | last post by:
Hi All: As a newbie to ASP.NET, I think I have understood a dataset as a kind of container where I can store several datatables to used during the lifetime of a page. With that in mind I written...
4
by: Jason Huang | last post by:
Hi, In my .Net 1.1 C# winodows form project, I use the following code trying to update data via a DataGrid. private void UpdateDataSet(DataSet myDataSet){...
1
by: sachinkale123 | last post by:
Hi I am working in a Windows C# application. I m using Dataset. But whenever I updated the dataset it gets updated. I can see the changes in dataset but using SQLAdapter.Update(Dataset) command It is...
1
by: adsaca | last post by:
database: MySQL i use connector i have two tables with the following contents: tbl_user_info user_id(Primary Key) fname lname
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.