代码中出现异常求解
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; }
}
}
}