Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    1

    Unanswered: Connecting to mysql with asp.net c#

    Hi all. this is the first time i have messed around with mysql, all i have is a headache. i'm using mysql 4.0.18 with ODBC driver 3.5 and using ASP.NET with C# to retreive data. i was just wondering if someone could help me connect to my Database. this is what i have so far.

    <%@ Page Language="C#" AutoEventWireup="False"
    EnableSessionState="False" EnableViewState="False" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.Odbc" %>

    <script runat="server">
    private const string ConnStr = "Driver={MySQL ODBC 3.51 Driver};" +
    "Server=localhost;Database=test;uid=root;pwd=yourp assword;option=3";

    protected override void OnInit(EventArgs e)
    {
    base.OnInit(e);

    using(OdbcConnection con = new OdbcConnection(ConnStr))
    using(OdbcCommand cmd = new OdbcCommand("SELECT * FROM Names", con))
    {
    con.Open();
    dgrAllNames.DataSource = cmd.ExecuteReader(
    CommandBehavior.CloseConnection |
    CommandBehavior.SingleResult);
    dgrAllNames.DataBind();
    }
    }
    </script>

    Is this right?

  2. #2
    Join Date
    Jan 2003
    Location
    Paris, France
    Posts
    320
    why not use a dot NET module ?

    http://dev.mysql.com/downloads/dotnet.html
    Olivier Miossec
    --
    http://www.lasso-developpeur.net/
    --

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •