What a ODBD connection strings look like :
http://www.asp101.com/articles/john/connstring/default.asp
How To Handle Multiple Results by Using the DataReader in Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;EN-US;311274
Connecting to MySQL database from your .NET applications -- introducing two methods.
http://www.codeproject.com/cs/database/ConnectMySQL.asp
Typed SQLDataReader
http://www.codeproject.com/cs/database/SmartReader.asp
ASP.NET: Accessing Data with C#
http://www.exforsys.com/content/view/1341/266/
MySQL 5 C# sample code using ObjectDataSources
http://www.codeproject.com/aspnet/MySQLCsharp.asp
Another way of connection in C#
Well I'm assuming you need to know how to use MySQL with C# in general so I'll post this...
I personally use the MySQL.DataClient when using MySQL with .NET so I'll post that, though there are other options, just google .NET and MySQL.
You can download them from:
http://dev.mysql.com/downloads/connector/net/1.0.html
Code:
using MySql.Data.MySqlClient;
Connection string...
private string connectionString = "Server=localhost;Database=yourtable;User ID=youruser;Password=yourpw;Pooling=false";
Main body...
MySqlConn.Open();
MySqlCommand MySqlCmd = MySqlConn.CreateCommand();
MySqlCmd.CommandText = "SELECT MAX(field) FROM table";
try
{
MySqlDataReader MySqlRead = MySqlCmd.ExecuteReader();
while (MySqlRead.Read())
{
Console.Write(MySqlRead.GetString(0));
}
MySqlRead.Close();
MySqlRead = null;
}
catch (MySqlException e)
{
Console.WriteLine(e.Message);
}
finally
{
MySqlConn.Close();
MySqlConn = null;
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Data.Odbc;
namespace myApplication
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : Page
{
protected System.Web.UI.WebControls.Button myButton;
public void butClick(object sender, System.EventArgs e)
{
string dbConnect; //Defines how we connect to MySQL
int count = 0; //Cycle through Records
OdbcConnection DB; //The MySQL Connection
OdbcCommand query; //The Query We Send
OdbcDataReader reader; // How we read the records
dbConnect = "driver={mysql ODBC 3.51 driver};server=localhost;port=3306;database=aspwork;uid=localhost;"; //Define how we connect
DB = new OdbcConnection( dbConnect ); //Define our connection
DB.Open(); //Open our connection
query = new OdbcCommand( "select * from testtable", DB );//Define our query
reader = query.ExecuteReader();//Execute the query
while( reader.Read() )//While we can read, read.
{
Response.Write( reader.GetString( count ) );//Write results
count++;//Increment our counter.
}
reader.Close();//Close our reader
DB.Close();//Close our connection
}
}
}