try
{
conn.Open();
//打开数据库
int
flag = insertcmd.ExecuteNonQuery();
//执行添加
if
(flag > 0)
//如果添加成功
{
Response.Write(
"<script language=javascript>alert('数据提交成功!')</script>"
);
this
.TextBox1.Text =
""
;
this
.TextBox2.Text =
""
;
this
.TextBox3.Text =
""
;
}
else
// 如果添加失败
{
Response.Write(
"<script language=javascript>alert('数据提交失败!')</script>"
);
this
.TextBox1.Text =
""
;
this
.TextBox2.Text =
""
;
this
.TextBox3.Text =
""
;
}
}
catch
(System.
Exception
ee)
//错误处理
{
Response.Write(
"<script language=javascript>alert('"
+ ee.Message.ToString() +
"')</script>"
);
}
finally
{
conn.Close();
//关闭数据库连接
}
}