473,499 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using C# with MySQL

Has anyone successfully used MySQL with C#?

I'm having problems using the Update command
Here is the code snippet. I am able to connect to the database. However when
I try to update the database with the changes in the dataset I get the
following error:

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.data.dll
Additional information: Dynamic SQL generation is not supported against a
SelectCommand that does not return any base table information.

public void setupConnection()
{
conString="Provider=MySQLProv;Data
Source=wedtest;SERVER=localhost;DB=wedtest;UID=adm in;PWD=password;PORT=3306"
;

myConnection=new OleDbConnection(conString) ;

string_sql="select * from Budget";

myDataSet = new DataSet();

myConnection.Open() ;

if(myConnection.State==ConnectionState.Open)

{

Console.WriteLine("Connection made");

}

myOleDbAdapter = new OleDbDataAdapter(string_sql,myConnection);

myOleDbAdapter.Fill(myDataSet,"Budget") ;

dataGrid1.DataSource = myDataSet.DefaultViewManager;
myCommandBuilder=new OleDbCommandBuilder(myOleDbAdapter);

}

public void updateRecord()

{

// Get all of the updated rows and update the datastore

updatedRows = myDataSet.GetChanges(System.Data.DataRowState.Modi fied);

if (((updatedRows) != (null)))

{

myOleDbAdapter.Update(updatedRows,"Budget");

}

}
-The Bear
Nov 15 '05 #1
4 7442
Hi,

Because the mysql syntax may be a bit constrained I would consider using properly verified DDL to update your data.

--
~~~~~~~~~~
Tommie Carter
tcarternyc(at)hotmail.com (messenger use)
--
"The Bear" <bu**********@hotmail.com> wrote in message news:cM******************@news20.bellglobal.com...
Has anyone successfully used MySQL with C#?

I'm having problems using the Update command
Here is the code snippet. I am able to connect to the database. However when
I try to update the database with the changes in the dataset I get the
following error:

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.data.dll
Additional information: Dynamic SQL generation is not supported against a
SelectCommand that does not return any base table information.

public void setupConnection()
{
conString="Provider=MySQLProv;Data
Source=wedtest;SERVER=localhost;DB=wedtest;UID=adm in;PWD=password;PORT=3306"
;

myConnection=new OleDbConnection(conString) ;

string_sql="select * from Budget";

myDataSet = new DataSet();

myConnection.Open() ;

if(myConnection.State==ConnectionState.Open)

{

Console.WriteLine("Connection made");

}

myOleDbAdapter = new OleDbDataAdapter(string_sql,myConnection);

myOleDbAdapter.Fill(myDataSet,"Budget") ;

dataGrid1.DataSource = myDataSet.DefaultViewManager;
myCommandBuilder=new OleDbCommandBuilder(myOleDbAdapter);

}

public void updateRecord()

{

// Get all of the updated rows and update the datastore

updatedRows = myDataSet.GetChanges(System.Data.DataRowState.Modi fied);

if (((updatedRows) != (null)))

{

myOleDbAdapter.Update(updatedRows,"Budget");

}

}
-The Bear
Nov 15 '05 #2
"The Bear" wrote ...
Has anyone successfully used MySQL with C#?
Yes... I'm using the MyODBC 3.51 driver.
I'm having problems using the Update command


I believe I remember reading something in the .NET Framework SDK about not
supporting the Insert, Update, or Delete auto-commands with the
OdbcDataAdapter. The documentation advises you to create your own command
structure.

Also, if the .NET OleDb provider works with MySQL, that's news to me. Are
you using MySQL OleDb? I don't think the .NET OleDb provider supports MySQL,
and I know MySQL-AB does not support the MySQL OleDb interface.

Why not use the Microsoft supported .NET 1.1 ODBC provider with the MySQL-AB
supported MyODBC 3.51 driver. At least you'll have more accurate
documentation that way, and some prior beta testing to rely on.

--
Regards,

Fred Chateau
e-mail: fchateauAtHotelMotelNowDotCom
Nov 15 '05 #3
The Bear,
You may want to look at the Mono driver implementation(s) for this. See
http://www.go-mono.com/mysql.html for the two available drivers. At least
they have source and are direct which should speed up performance.

Ron Allen
"The Bear" <bu**********@hotmail.com> wrote in message
news:cM******************@news20.bellglobal.com...
Has anyone successfully used MySQL with C#?

I'm having problems using the Update command
Here is the code snippet. I am able to connect to the database. However when I try to update the database with the changes in the dataset I get the
following error:

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.data.dll
Additional information: Dynamic SQL generation is not supported against a
SelectCommand that does not return any base table information.

public void setupConnection()
{
conString="Provider=MySQLProv;Data
Source=wedtest;SERVER=localhost;DB=wedtest;UID=adm in;PWD=password;PORT=3306" ;

myConnection=new OleDbConnection(conString) ;

string_sql="select * from Budget";

myDataSet = new DataSet();

myConnection.Open() ;

if(myConnection.State==ConnectionState.Open)

{

Console.WriteLine("Connection made");

}

myOleDbAdapter = new OleDbDataAdapter(string_sql,myConnection);

myOleDbAdapter.Fill(myDataSet,"Budget") ;

dataGrid1.DataSource = myDataSet.DefaultViewManager;
myCommandBuilder=new OleDbCommandBuilder(myOleDbAdapter);

}

public void updateRecord()

{

// Get all of the updated rows and update the datastore

updatedRows = myDataSet.GetChanges(System.Data.DataRowState.Modi fied);

if (((updatedRows) != (null)))

{

myOleDbAdapter.Update(updatedRows,"Budget");

}

}
-The Bear

Nov 15 '05 #4
"Ron Allen" wrote ...
You may want to look at the Mono driver implementation(s) for this. See

http://www.go-mono.com/mysql.html for the two available drivers. At least
they have source and are direct which should speed up performance.

When I first set up a MySQL database on my server, I tried several methods
to connect my code. I was pretty excited after locating a .NET driver that
directly connected to the MySQL database, since this seemed to be the most
efficient way to do it.

One evening the driver locked up my server so hard, I wound up driving 30
miles to the co-location site to unplug the machine so I could restart it.
When working with a production server, I don't need that kind of aggravation
.. . .

I switched to the ODBC interface, and haven't had any problems since. Also,
I don't doubt that there's a performance gain when using a single layer or
direct connection, but my application is assembling Web pages on-the-fly
using the data in the MySQL database, and I haven't been able to tell the
difference between the two drivers.

--
Regards,

Fred Chateau
e-mail: fchateauAtHotelMotelNowDotCom
Nov 15 '05 #5

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

Similar topics

5
3241
by: Phil Powell | last post by:
I've read some online resources that utilize various MySQL command-line actions to migrate data from Access to MySQL. The situation is this: a group of co-workers of mine will be using an Access...
6
3855
by: das dsf | last post by:
Hi there! I have both PHP 4.0( RPM) installed and MySQL 4.0.20 installed with the mysqld daemon up and running. But when I look at the output of phpinfo() , I do not see it there, which is...
2
1759
by: cocoalearner | last post by:
I am serving a website using apache. All the php and mysql code I have written works, except for one thing. When I try to create a database named M#2 using the following call, no database is...
0
2454
by: Tawfik Rady | last post by:
Hi Everybody, 1- I am trying to upsize an access database to my MySQL server on my website. I tried to get connected within access and failed. Please advise. I am using Win XP as the operating...
0
2393
by: Mark | last post by:
Using a Java program, I can connect to the test database in MySQL. The test database is installed using a MySQL utility, and it can be accessed by any user without supplying a password. The...
1
1885
by: Ted | last post by:
I managed to get it installed OK, along side MS Visual Studio 2005 (with which I received it). During the install, I made sure I installed everything. I have developed a number of applications...
4
3034
by: yogesh | last post by:
mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... #include <stdio.h> #include <mysql.h> #include <string.h> int main() {
12
3341
by: MJK | last post by:
Hello everybody, I am almost a new C programmer and now I need to use SQL within my C codes. Does anybody have any idea about good examples on SQL using C? I have not any experience using SQL...
221
366942
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
8
2125
by: NMarks | last post by:
Hello all, I have created a database for my work that stores information for keys/locks, doors and employees. Specifically the database contains all the information of our lock system, which...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.