Visual Studio C# Express - MySQL

I

Iain

Hi

Is it possible to get Visual Studio C# Express (beta 2) connecting to a
MySQL database?

TIA
Iain
 
S

scott blood

Iain,

Unfortunatly you cannot visually connect to MySQL through C# Express, i dont
know why, i think this is just one of the limitations of C# Express.

However, you can use ODBC to connect to MySQL through code, so long as you
know the ODBC Connection string to use. Please have a look at the following
code snippet.


using System.Data.Odbc;
using System.Data;

private void GetDataFromMySQL()
{
string connStr = "";

// i am not sure what the connection string for MySql would be, i think it
might "Provider=MySQLProv;Data Source=mydb;User
Id=UserName;Password=asdasd;"


using (OdbcConnection odbcCon = new OdbcConnection(connStr))
using (OdbcCommand odbcCom = new OdbcCommand("Select * From Product",
odbcCon))
using (OdbcDataAdapter odbcDA = new OdbcDataAdapter(odbcCom))
using (DataSet ds = new DataSet())
{
odbcCon.Open();
odbcDA.Fill(ds);
/** Now that we have it in a DataSet, we can do what you want with it: f
your controls...
**/
this.dataGridView1.DataSource = ds.Tables[0];
}

}

Hope this helps

Regards

Scott Blood

C# Developer
 
D

Duncan Mole

MySQL actually have a .net data provider, you could consider this over ODBC.

scott blood said:
Iain,

Unfortunatly you cannot visually connect to MySQL through C# Express, i
dont know why, i think this is just one of the limitations of C# Express.

However, you can use ODBC to connect to MySQL through code, so long as you
know the ODBC Connection string to use. Please have a look at the
following code snippet.


using System.Data.Odbc;
using System.Data;

private void GetDataFromMySQL()
{
string connStr = "";

// i am not sure what the connection string for MySql would be, i think it
might "Provider=MySQLProv;Data Source=mydb;User
Id=UserName;Password=asdasd;"


using (OdbcConnection odbcCon = new OdbcConnection(connStr))
using (OdbcCommand odbcCom = new OdbcCommand("Select * From Product",
odbcCon))
using (OdbcDataAdapter odbcDA = new OdbcDataAdapter(odbcCom))
using (DataSet ds = new DataSet())
{
odbcCon.Open();
odbcDA.Fill(ds);
/** Now that we have it in a DataSet, we can do what you want with it:
f your controls...
**/
this.dataGridView1.DataSource = ds.Tables[0];
}

}

Hope this helps

Regards

Scott Blood

C# Developer





Iain said:
Hi

Is it possible to get Visual Studio C# Express (beta 2) connecting to a
MySQL database?

TIA
Iain
 
S

scott blood

Mark,

The question never specified a type of connection required, so i assumed
ODBC as this does not require third party .net providers which may or may
not be supported in C# Express. All that is required is the ODBC driver.

Plus the use of ODBC enables you with little or no changes to your code,
other than the provider, to change your data server or file quite quickly,
where as the likes of SqlClient is specifically for Sql Server and is a lot
of work chaning this to another server type.

Regards
Scott Blood
C# Developer
 
G

Guest

If the .NET MySql Provider is well - written, it will have registration file
to register the type for designer visibility. Then the provider will appear
in the list of connection types.
Peter
 
S

scott blood

Peter,

I have just had a look at it myself and it is quite well written actually,
but , i though visual c# express didnt support visual designers for third
party dataa providers????? If it does then why cant every just download
visual c# express and start developing with that and then pay the small
license fee for the proffesional version only if your happy with what you
will be distributing.

Regards
Scott Blood
C# Developer
 
S

scott blood

Which brings brings me back to my origonal post, use ODBC this is fully
supported.

Regards
Scott Blood
C# Developer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top