| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 717 人关注过本帖
标题:代码中出现异常求解
只看楼主 加入收藏
顾帆
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2011-11-12
结帖率:60%
收藏
已结贴  问题点数:8 回复次数:2 
代码中出现异常求解
public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string v_strAction = context.Request["action"];
            DbHelper db = new DbHelper();
            int n = -1;
            switch (v_strAction)
            {
                case "select":
                    string v_strSelect = context.Request["text"];
                    //string select = "select * from 测评";
                    //OleDbDataReader dr = db.ExecuteReader(select);
                    string s = "";
                    //测评 s = new 测评();
                    //while (dr.Read())
                    //{
                    //    db.AddParameter("测评ID", s.测评ID);
                    //    db.AddParameter("测评人工号", s.测评人工号);
                    //    db.AddParameter("被测人工号", s.被测评人工号);
                    //    db.AddParameter("测评项ID", s.测评项ID);
                     
                    //}

                    db.AddParameter("like", string.Format("%{0}%", v_strSelect));
                    DataTable table = db.ExecuteDataTable("select * from 测评 where 测评ID like@like  测评人工号like@like or 被测人工号like @like 测评项ID like @like order by 测评ID");
                    foreach (DataRow row in table.Rows)
                    {
                        s += string.Format("&记录&{0}&字段&{1}&字段&{2}&字段&{3}",
                            row["测评ID"], row["测评人工号"], row["被测人工号"], row["测评项ID"]);
                    }
                    s = s.Substring("&记录&".Length);
                    db.Dispose();
                    context.Response.Write(s);
                   break;

                case "insert":

                    string v_strInsert = context.Request["text"];
                    string[] fields = v_strInsert.Split(new string[] { "~~" }, StringSplitOptions.None);


                    db.AddParameter("测评ID", fields[0]);
                    db.AddParameter("测评人工号", fields[1]);
                    db.AddParameter("被测人工号", fields[2]);
                    db.AddParameter("测评项ID", double.Parse(fields[3]));
                    try
                    {
                        n = db.ExecuteNonQuery("insert into 测评 values(@测评ID,@测评人工号,@被测人工号,@测评项ID)");
                        if (n > 0)
                            context.Response.Write("OK");
                        else
                            context.Response.Write("");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    finally
                    {
                        db.Dispose();
                    }
                    break;
                case "update":

                    string v_strUpdate = context.Request["text"];
                    string[] fields_Update = v_strUpdate.Split(new string[] { "~~" }, StringSplitOptions.None);

                    db.AddParameter("测评人工号", fields_Update[1]);
                    db.AddParameter("被测人工号", fields_Update[2]);
                    db.AddParameter("测评项ID", double.Parse(fields_Update[3]));
                    db.AddParameter("测评ID", fields_Update[0]);
                    try
                    {
                        n = db.ExecuteNonQuery("update 测项 set 测评人工号=@测评人工号,被测人工号=@被测人工号,测评项ID=@测评项ID where 测项ID=@测项ID");
                        if (n > 0)
                            context.Response.Write("OK");
                        else
                            context.Response.Write("");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    finally
                    {
                        db.Dispose();
                    }
                    break;
                case "delete":

                    string v_strDelete = context.Request["text"];

                    db.AddParameter("测项ID", v_strDelete);
                    try
                    {
                        n = db.ExecuteNonQuery("delete from 测项 where 测项ID=@测评ID");
                        if (n > 0)
                            context.Response.Write("OK");
                        else
                            context.Response.Write("");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    finally
                    {
                        db.Dispose();
                    }
                    break;
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        public class 测评
        {
            public string 测评ID { get; set; }
            public string 测评人工号 { get; set; }
            public string 被测评人工号 { get; set; }
            public string 测评项ID { get; set; }
        }
    }
}
搜索更多相关主题的帖子: class public 
2012-01-02 13:15
yinniannian
Rank: 9Rank: 9Rank: 9
来 自:河北省石家庄
等 级:蜘蛛侠
威 望:2
帖 子:256
专家分:1007
注 册:2011-5-13
收藏
得分:8 
贴出错误来

代做小型软件。
QQ:449795473
2012-01-04 17:53
sterling
Rank: 2
等 级:论坛游民
帖 子:10
专家分:20
注 册:2012-1-12
收藏
得分:0 
switch (v_strAction)
            {
                case "select":

....

一般编程不会吧String 作为 case后面的值,这样要是做本地化的话,就已经不成功了这个程序。
eg: 英语select
    中文 选择
这两者的string可不一样的。。。
2012-01-12 17:28
快速回复:代码中出现异常求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017668 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved