日期:2014-05-17  浏览次数:20701 次

我写了一个ajax方法,但是为什么后台第一遍执行完后又回到第一行重新执行到command.Fill(ds);就报错?
后台
 public void ProcessRequest(HttpContext context)
        {
            SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123456;database=CMSDB");
            //连接SQL数据库
            int action = Convert.ToInt32(context.Request.QueryString["action"]);

            if (action == 1)
            {
                DataSet ds = new DataSet();
                conn.Open();
                string articleId = context.Request.QueryString["article"];//后台ajax传人的文章Id
                string sql = string.Format("select * from cms_expression where article_id ={0}", articleId);
                SqlDataAdapter command = new SqlDataAdapter(sql, conn);
                command.Fill(ds););//第二遍执行到这里报错,正常情况应该是只执行一遍就把数据传到前台
                DataRow dr = ds.Tables[0].Rows[0];
                conn.Close();
                int a = Convert.ToInt32(dr["article_id"].ToString());
                int b = Convert.ToInt32(dr["glad"].ToString());
                int c = Convert.ToInt32(dr["moved"].ToString());

                LitJson.JsonData json = new LitJson.JsonData();
                context.Response.ContentType = "application/json";

                json["id"] = a;