Click here to Skip to main content
15,919,434 members

Comments by dontnetzone (Top 1 by date)

dontnetzone 24-Apr-14 8:31am View    
hi Manoj,

I am using Mysql database.

Inserting into the table is successful, but the below code for retrieving the data has encountered one problem.

MysqlDataReader dr;

The above line is showing error "The type or namespace MysqlDataReader could not be found."

I have already done the reference part for Mysql.Data, still getting the issue.

What could be the problem.

Code below.



protected void Button2_Click(object sender, EventArgs e)
{

string connStr = "Server=localhost;Database=mysqldb;Uid=uid;Pwd=******$$;";
string intersts = "";

using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(connStr))
{

MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = conn;
// SqlCommand cmd = new SqlCommand("Select Interests from Demo", cn); // Write your Query i have taken as sample
cmd.CommandText = "Select areas from area_of_interests ";

MysqlDataReader dr;

//SqlDataReader dr;
conn.Open();

dr = cmd.ExecuteReader();
if (dr.Read())
{
intersts = dr["Interests"].ToString();
}
conn.Close();
string[] arr = intersts.Split(',');
foreach (ListItem item in this.CheckBoxList1.Items)
{
foreach (string s in arr)
{
if (item.Text == s)
{
item.Selected = true;
}
}
}

}
}

--
dotnetzone.