注册 登录
编程论坛 ASP.NET技术论坛

为什么我在添加信息时,会出现这样个错误:发生类型为System.Web.HttpUnhandledExc

水晶之恋 发布于 2007-05-17 09:10, 1761 次点击
为什么我在添加信息时,会出现这样个错误:
发生类型为System.Web.HttpUnhandledException的异常
11 回复
#2
bygg2007-05-17 09:21
把相关的代码发出来吧...这样谁也不知道是什么错..
#3
水晶之恋2007-05-17 09:29
private void add_Click(object sender, System.EventArgs e)
{ strsql="insert into users(username,sex,hometown,nation,birth,health,marry,political,address,mobilephone,homephone,email,gra_school,zhuanye,xueli,gra_time,work_time,dep_name,zhiwu,type,constract_time,cancel_time,PicUrl) values ( ";

strsql+="'" + username.Text + "'";
strsql+="'" + sex.SelectedValue + "'";
strsql+="'" + hometown.Text + "'";
strsql+="'" + nation.Text + "'";
strsql+="'" + birth.Text + "'";
strsql+="'" + health.Text + "'";
strsql+="'" + marry.SelectedValue + "'";
strsql+="'" + political.Text + "'";
strsql+="'" + address.Text + "'";
strsql+="'" + mobilephone.Text + "'";
strsql+="'" + homephone.Text + "'";
strsql+="'" + email.Text + "'";
strsql+="'" + gra_school.Text + "'";
strsql+="'" + zhuanye.Text + "'";
strsql+="'" + xueli.SelectedValue + "'";
strsql+="'" + gra_time.Text + "'";
strsql+="'" + work_time.Text + "'";
strsql+="'" + dep_name.SelectedValue + "'";
strsql+="'" + zhiwu.Text + "'";
strsql+="'" + type.SelectedValue + "'";
strsql+="'" + constract_time.Text + "'";
strsql+="'" + cancel_time.Text + "'";
strsql+=url;
strsql+=")";

com=new SqlCommand(strsql,conn);
conn.Open();
com.ExecuteNonQuery();
com.Dispose();
conn.Close();
Response.Write("<script>javascript:alert('添加成功!!!');</script>");
// Response.Redirect("add_person.aspx?users_id=");
}
#4
冰镇柠檬汁儿2007-05-17 09:35

.NET Framework 类库
HttpUnhandledException 类
发生一般异常时引发的异常。

命名空间:System.Web
程序集:System.Web(在 system.web.dll 中)

语法

Visual Basic(声明)
<SerializableAttribute> _
Public NotInheritable Class HttpUnhandledException
Inherits HttpException

Visual Basic(用法)
Dim instance As HttpUnhandledException

C#
[SerializableAttribute]
public sealed class HttpUnhandledException : HttpException

C++
[SerializableAttribute]
public ref class HttpUnhandledException sealed : public HttpException

J#
/** @attribute SerializableAttribute() */
public final class HttpUnhandledException extends HttpException

JScript
SerializableAttribute
public final class HttpUnhandledException extends HttpException

继承层次结构

System.Object
System.Exception
System.SystemException
System.Runtime.InteropServices.ExternalException
System.Web.HttpException
System.Web.HttpUnhandledException

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。

版本信息

.NET Framework
受以下版本支持:2.0、1.1、1.0

#5
冰镇柠檬汁儿2007-05-17 09:37
楼主啊,你values里的值之间怎么没有“,”
#6
Kendy1234562007-05-17 09:46
错是这个错 但是报出来应该是sql异常呀 为什么报了个无法标识的异常呢
#7
水晶之恋2007-05-17 09:56
private void add_Click(object sender, System.EventArgs e)
{
try
{
string strsql;

strsql="insert into users(username,sex,hometown,nation,birth,health,marry,political,address,mobilephone,homephone,email,gra_school,zhuanye,xueli,gra_time,work_time,dep_name,zhiwu,type,constract_time,cancel_time,PicUrl)";
strsql+=" + values( +";

strsql+="'" + username.Text + "'";
strsql+="'" + sex.SelectedValue + "'";
strsql+="'" + hometown.Text + "'";
strsql+="'" + nation.Text + "'";
strsql+="'" + birth.Text + "'";
strsql+="'" + health.Text + "'";
strsql+="'" + marry.SelectedValue + "'";
strsql+="'" + political.Text + "'";
strsql+="'" + address.Text + "'";
strsql+="'" + mobilephone.Text + "'";
strsql+="'" + homephone.Text + "'";
strsql+="'" + email.Text + "'";
strsql+="'" + gra_school.Text + "'";
strsql+="'" + zhuanye.Text + "'";
strsql+="'" + xueli.SelectedValue + "'";
strsql+="'" + gra_time.Text + "'";
strsql+="'" + work_time.Text + "'";
strsql+="'" + dep_name.SelectedValue + "'";
strsql+="'" + zhiwu.Text + "'";
strsql+="'" + type.SelectedValue + "'";
strsql+="'" + constract_time.Text + "'";
strsql+="'" + cancel_time.Text + "'";
strsql+="'" + url + "'";
strsql+=")";
com=new SqlCommand(strsql,conn);
conn.Open();
com.ExecuteNonQuery();

Response.Write("<script>javascript:alert('添加成功!!!');</script>");
Response.Redirect("default.aspx");
}
catch(Exception ee)
{
Response.Write("出现异常错误!");
throw ee;
}

}
com.Dispose();
conn.Close();
}
#8
bygg2007-05-17 10:30
就是SQL的错误,你加了TRY..CATCH..说的是什么错?
#9
水晶之恋2007-05-17 10:41

我加入信息后,就是那个错
sql语句是不是应该改成:

strsql="insert into users(username,sex,hometown,nation,birth,health,marry,political,address,mobilephone,homephone,email,gra_school,zhuanye,xueli,gra_time,work_time,dep_name,zhiwu,type,constract_time,cancel_time,PicUrl)";
strsql+=" + values( +";

strsql+="'" + username.Text + "'";
strsql+=","; //是不是都加入这句
strsql+="'" + sex.SelectedValue + "'";
strsql+="'" + hometown.Text + "'";
strsql+="'" + nation.Text + "'";
strsql+="'" + birth.Text + "'";
strsql+="'" + health.Text + "'";
strsql+="'" + marry.SelectedValue + "'";
strsql+="'" + political.Text + "'";
strsql+="'" + address.Text + "'";

#10
fqbnet20082007-05-17 10:43
strsql+="'" + username.Text + "'";
strsql+="'" + sex.SelectedValue + "'";

你这么写是不是清楚一些呢?
strsql+="'" + username.Text + "',' ";
strsql+= sex.SelectedValue + "',' ";
........
strsql+= username.Text + "',' ";
strsql+= sex.SelectedValue + "') ";

最后别忘了加小括号。

#11
水晶之恋2007-05-17 11:02
strsql+= username.Text + "',' ";
strsql+= sex.SelectedValue + "') ";
还是用这个清楚点,比
strsql+="'" + username.Text + "',' ";
strsql+= sex.SelectedValue + "',' ";
........
清楚
#12
Kendy1234562007-05-17 11:43
代码格式是另外回事 你搞清除问题出在哪里就行了
1