Question:

What is the procedure to connect MYSQL with ASP.NET?

by  |  earlier

0 LIKES UnLike

I want to develop a new software by using MYSQL as backend , I don't know how to get the provider, there is no default provider in my system. I am using Microsoft .NET 2003 Edition

 Tags:

   Report

1 ANSWERS


  1. You can connect with MySQL by using ODBC. You have to use the following library in the begining of your code:

    using System.Data.Odbc;

    he following code will explain how to connect with a MySQL 4.1 database:

    // Connection String

    private const string ConnStr =

       "Driver={MySQL ODBC 3.51 Driver};Server=localhost;" +

       "Database=test;uid=root;pwd=;option=3";

    // DataBinding

    private void BindDataGrid()

    {

        using(OdbcConnection con = new OdbcConnection(ConnStr))

        using(OdbcCommand cmd =

              new OdbcCommand("SELECT * FROM Sample", con))

        {

            con.Open();

            DataGrid1.DataSource = cmd.ExecuteReader(

                        CommandBehavior.CloseConnection |

                        CommandBehavior.SingleResult);

            DataGrid1.DataBind();

        }

    }

    If you have any other question, please feel free to email me at maqsood_rahman@hotmail.com.

    Wish you best of luck.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.