O
onearth
Hello
I managed to use SQL EXPRESS easily, however with MySql 5 or 4 I can't
find any document explainning me how to use it
The error i get is: The IListSource does not contain any data sources.
on the line GridView1.DataBind();
I guess i missed using SQLDataSource Control... i do not know what to
do with it to make it work with MySql.
What i did:
using MySql.Data.MySqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String queryString = "select * from mytest";
DataSet ds = GetData(queryString);
GridView1.DataSource = ds;
GridView1.DataBind();
}
DataSet GetData(String queryString)
{
try
{
DataSet ds = new DataSet();
// Connect to the database and run the query.
MySqlConnection conn = new
MySqlConnection("server=localhost; user id=root; password=blabla;
database=test2; pooling=false;");
MySqlDataAdapter adapter = new
MySqlDataAdapter(queryString, conn);
// Fill the DataSet.
adapter.Fill(ds);
}
catch (Exception ex)
{
// The connection failed. Display an error message.
Message.Text = "Unable to connect to the database.";
}
return ds;
}
}
Regards,
onear
and hope someone knows what to do..
I managed to use SQL EXPRESS easily, however with MySql 5 or 4 I can't
find any document explainning me how to use it
The error i get is: The IListSource does not contain any data sources.
on the line GridView1.DataBind();
I guess i missed using SQLDataSource Control... i do not know what to
do with it to make it work with MySql.
What i did:
using MySql.Data.MySqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String queryString = "select * from mytest";
DataSet ds = GetData(queryString);
GridView1.DataSource = ds;
GridView1.DataBind();
}
DataSet GetData(String queryString)
{
try
{
DataSet ds = new DataSet();
// Connect to the database and run the query.
MySqlConnection conn = new
MySqlConnection("server=localhost; user id=root; password=blabla;
database=test2; pooling=false;");
MySqlDataAdapter adapter = new
MySqlDataAdapter(queryString, conn);
// Fill the DataSet.
adapter.Fill(ds);
}
catch (Exception ex)
{
// The connection failed. Display an error message.
Message.Text = "Unable to connect to the database.";
}
return ds;
}
}
Regards,
onear
and hope someone knows what to do..