无法将类型object隐式转换为int存在一个显式转换

.Net技术 码拜 10年前 (2014-12-14) 3170次浏览 0个评论

为什么 if (mysqlReader2[0].ToString() != “0” )
这句提示:
错误 1 无法将类型“object”隐式转换为“int”。存在一个显式转换(是否缺少强制转换?)
代码如下:
connection = new MySql.Data.MySqlClient.MySqlConnection(MyConnectionString);

 
                connection.Open();
               
                MySqlCommand cmd_board = connection.CreateCommand();
                MySqlCommand cmd_board2 = connection.CreateCommand();
               cmd_board.CommandText = "SELECT wr_2 FROM gs_write_" + config.my_serv_table + " WHERE wr_1 != 1 AND wr_subject !='' LIMIT 0,5 ";
                cmd_board2.CommandText = "SELECT count(*) as count1 FROM gs_write_" + config.my_serv_table + " WHERE wr_1 != 1 AND wr_subject !='' LIMIT 0,5 ";
                MySql.Data.MySqlClient.MySqlDataReader mysqlReader1 = cmd_board.ExecuteReader();
                MySql.Data.MySqlClient.MySqlDataReader mysqlReader2 = cmd_board2.ExecuteReader();
                if (mysqlReader2[0].ToString() != "0" )
                {
                    linkLabel1.Text = "";
                    while (mysqlReader1.Read())
                    {
                        if (mysqlReader1["wr_2"].ToString().Length > 10)
                        {
                            linkLabel1.Text += "\n" + mysqlReader1["wr_2"].ToString().Substring(0, 10) + "\n";
                        }
                        else
                        {
                            linkLabel1.Text += "\n" + mysqlReader1["wr_2"].ToString() + "\n";
                        }
                    }
                }

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明无法将类型object隐式转换为int存在一个显式转换
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!