- C# code
[WebMethod(Description = "内容信息")] public string ContentInfo(string param) { string total = ""; string result_head = "<contents>"; string result_foot = "</contents>"; string result = ""; string query = "select * from talk left join reply on talk.id='"+param+"' and reply.rid='"+param+"' where reply.rid is not null"; MySqlConnection myConnection = new MySqlConnection("server=localhost;user=xxxx;password=xxx;database=xxx;charset=utf8"); DataSet ds = new DataSet(); DataTable dtable; DataRowCollection dc; DataRow drow; myConnection.Open(); MySqlDataAdapter sqld = new MySqlDataAdapter(query, myConnection); sqld.Fill(ds, "con"); dtable = ds.Tables["con"]; dc = dtable.Rows; if (dc.Count == 0) {//运行这里的查询出错 ds.Clear(); MySqlDataAdapter sqld2 = new MySqlDataAdapter("select * from talk,reply where talk.id='" + param + "' and reply.fuzhuid=1", myConnection); sqld2.Fill(ds, "con2"); DataTable dtable2 = ds.Tables["con2"]; DataRowCollection dc2 = dtable2.Rows; dc2 = dtable2.Rows; for (int i = 0; i < dc2.Count; i++) { DataRow drow2 = dc2[i]; //此处省略 } total = result_head + result + result_foot; } else {//运行这里的查询没问题,正常显示数据 for (int i = 0; i < dc.Count; i++) { drow = dc[i]; //此处省略 } total = result_head + result + result_foot; myConnection.Close(); } return total; }
为什么会错啊。。。有什么好的代码替换替换
------解决方案--------------------------------------------------------
没有看懂你是什么意思,
------解决方案--------------------------------------------------------
仔细检查一下吧