MysqlDataReader不适用于asp.net(c#) [英] MysqlDataReader not working for asp.net (c#)

查看:145
本文介绍了MysqlDataReader不适用于asp.net(c#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

我正在使用Mysql数据库。



将复选框列表的值插入mysql表是成功的,但是以下用于检索数据的代码遇到了一个问题。



MysqlDataReader dr;



以上行显示错误无法找到类型或命名空间MysqlDataReader。



我已经完成了Mysql.Data的参考部分,仍然遇到问题。



可能是什么问题?



以下代码。





hi
I am using Mysql database.

Inserting the values of the Checkbox list into into the mysql 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;
                  }
              }
          }

      }
  }

推荐答案

;;
string intersts = ;

使用(MySql.Data.MySqlClient.MySqlConnection conn = < span class =code-keyword> new MySql.Data.MySqlClient.MySqlConnection(connStr))
{

MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = conn;
// SqlCommand cmd = new SqlCommand(从Demo中选择兴趣,cn); //编写我的查询我已作为样本
cmd.CommandText = 从area_of_i中选择区域nterests;

MysqlDataReader dr;

// SqlDataReader dr;
conn.Open() ;

dr = cmd.ExecuteReader();
if (dr.Read())
{
intersts = dr [ 兴趣]。ToString();
}
conn.Close();
string [] arr = intersts.Split(' );
foreach (ListItem item in this .CheckBoxList1.Items)
{
foreach string s 中的class =code-keyword> arr)
{
if (item.Text == s)
{
item.Selected = true ;
}
}
}

}
}
;"; 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; } } } } }


它应该是 MySqlClient 注意Sql中的大写 S



c#就是这种情况敏感。

it should be MySqlClient note that capital S in Sql

c# is case sensitive.
Quote:

在Visual Studio中,您可以通过点击Control-Space来解决这个问题。 />
这将自动完成您输入的内容,并修复外壳。如果你已经键入了messagebox,并且当你的cusor在那里时,点击控制空间,那么它会将它改为MessageBox。

In Visual Studio, you can work around this by hitting "Control-Space" alot.
This will auto-complete what you're typing, and fix the casing. If you're
already typed "messagebox", and hit "Control-Space" while your cusor is in
there, it'll change it to "MessageBox".



查看此论坛帖子 [ ^ ]


hi全部,



添加引用时出现问题。一旦修复,问题就解决了。



当然,也使用了区分大小写的拼写。



感谢所有人。



--bdhkrl。
hi All,

There was an issue with adding reference. Once that was fixed, the issue got resolved.

Of course, right case sensitive spelling was also used.

thanks to all.

--bdhkrl.


这篇关于MysqlDataReader不适用于asp.net(c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆