为什么 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"; } } }