connecting to mysql DB

I am very new to C# and programming. I am using Visual trial version. I have a mysql DB for my PHP website. Could some one explain in simple terms how I would connect to this. I went to toolbox and tried oledbdatapter but the only options i was given by the wizard was to microsoft databases ie jet etc....
any hints on querying would be good as well. cheers.
Who is Participating?
dunglaConnect With a Mentor Commented:
Solution 1:

You can go to this website to download MySQLDirect .NET Data Provider

then you can use following code
// using name space
using eInfoDesigns.dbProvider.MySqlClient;
// create connection
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "my connectionstring";

Solution 2: using OleDB

OleDbConnection cn = new OleDbConnection( "Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;");
In the web.config file for your website

              <add key="connString" value="server=localhost;Uid=Username;Password=YourPassword;Database=YourDB" />

Then a simple page

<%@ Page Language="C#" ContentType="text/html" debug="true"%>
<%@ Import Namespace="MySql.Data.MySqlClient" %>
<%@ Import Namespace="System.Data" %>

<script language="c#" runat="server">

void Page_Load()
      MySqlConnection objConn = new MySqlConnection(ConfigurationSettings.AppSettings["connString"]);
        string sqlQuery = "SELECT * FROM yourtable ";
        MySqlCommand objCmd = new MySqlCommand(sqlQuery, objConn);
        MySqlDataAdapter da = new MySqlDataAdapter();
        DataSet ds = new DataSet();
      da.SelectCommand = objCmd;
      da.Fill(ds, "MyTable");
        Myrepeater.DataSource = ds.Tables["MyTable"];
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">

<asp:Repeater ID="Myrepeater" runat="server">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "FeildName")%></ItemTemplate>

Of course there are other ways to do it, including binding the dataset directly, geting a dataReader, etc depending on what you want to be doing....
jdav3579Author Commented:
I presume this is for an  page? What I am trying to do is make a stand alone program on the computer using c# that when it requires information it just goes to my websites database to get it. also new information is then sent to and updates the site. I wrote my website in PHP. So is it possible to just connect to the DB, someone said with an OBDC I think. As a later project I am going to have a temperature sensor which is connected via serial port that sends current temperature to my websites database. Then the website displays this. Thats as a later project though.
try to think about using myODBC rathen connect mySQL directly! you can download myODBC from or
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.