Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using VS 2008.

Looking around on the forums/stack hasn't provided a clear answer on how to use MySQL with a ASP .NET site.

How do I configure a SQLDataSource to use MySQL by using the MySQL Connector NET provider?

I would prefer not to use the ODBC driver - which I can get working. The connector has been added as a reference to the project and appears in the web.config as:

<add assembly="MySql.Data, Version=5.2.2.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>

And I also attempted to manually create a section under :

<add name="MYSQL" connectionString="Server=localhost;Database=data;Uid=root;Pwd=1234;" providerName="MySql.Data" />

The MySQL Connector version that I have is 5.2.2.0

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

MySQl and ASP.NET tutorial

maybe this will help?

share|improve this answer
 
Thanks for the link. –  John M Jul 1 '09 at 13:13
add comment

The C# version of creating a basic MySQL connection is:

<%@ Page Language="C#" debug="true" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<script language="C#" runat="server">

private void Page_Load(Object sender ,EventArgs e)
{   
    MySqlConnection myConnection = new MySqlConnection();
    MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
    DataSet myDataSet = new DataSet();
    string strSQL;
    int iRecordCount;

    myConnection = new MySqlConnection("server=localhost; user id=root; password=ii33uuqwerty; database=wlc_data; pooling=false;");

    strSQL = "SELECT * FROM troutetracking LIMIT 100;";

    myDataAdapter = new MySqlDataAdapter(strSQL, myConnection);
    myDataSet = new DataSet();
    myDataAdapter.Fill(myDataSet, "mytable");

    MySQLDataGrid.DataSource = myDataSet;
    MySQLDataGrid.DataBind();

}

Simple MySQL Database Query

share|improve this answer
add comment

in web.conf file, you add following lines: <connectionStrings> <add name="connMysql" connectionString ="Server=localhost;Database=transcode;Uid=root;" providerName="MySql.Data.MySqlClient"/> </connectionStrings>

in .aspx file you can add following lines:

<asp:SqlDataSource ID="Datacmd" runat="server" ConnectionString="<%$ConnectionStrings:connMysql %>" ProviderName="<%$ ConnectionStrings:connMysql.providerName%>" SelectCommand="SELECT command.id,server.ip,command.name,command.cmd,command.input_ip,command.output_ip,command.pid,command.status FROM server,command WHERE command.server_id=server.id " </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" DataSourceID="Datacmd" AutoGenerateColumns="False" ForeColor="#003300"> <Columns> ............................. </Columns> </asp:GridView>

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.