Re: Sample code for mysql and Visual Web Developer
Posted by: GAY SANDIQUE
Date: November 28, 2006 06:21PM

I tried using the mysql .net connector 1.0.7 with visual web developer.
1. First you need to add reference to the mysql.data.dll file.
Click WebSite/Add Reference/Browse tab, then look for this file.
C:\Program Files\MySQL\MySQL Connector Net 1.0.7\bin\.NET 1.0\MySql.Data.dll
2. I added web.config file in the website project. and added the
connection string.
<connectionStrings>
<add name="myconnection" connectionString="datasource=yourcomputername;uid=root;pwd=yourpassword;database=yourdatabase;"/>
</connectionStrings>

3. Let say you want to add a gridview control in the default.aspx
form. Here's is the sample code.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using MySql.Data.MySqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str1 = ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;
MySqlConnection conn;
conn = new MySqlConnection(str1);
conn.Open();
DataSet ds1 = new DataSet();
MySqlDataAdapter da1 = new MySqlDataAdapter("select * from tblItem", conn);
da1.Fill(ds1, "tblItem");
GridView1.DataSource = ds1.Tables["tblItem"];
GridView1.DataBind();
}
}

I hope this helps.

Options: ReplyQuote


Subject
Written By
Posted
Re: Sample code for mysql and Visual Web Developer
November 28, 2006 06:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.