.aspx文件的c#语句中的response.write(“添加成功”);为什么不起作用,源代码如下,求大神帮忙
<scriptrunat="server"language="C#">voidEnter_click(ObjectSender,EventArgsE){//建立Conne...
<script runat="server" language="C#">
void Enter_click(Object Sender, EventArgs E)
{
//建立Connection对象
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/database/data.mdb"));
//建立Command对象
conn.Open(); //打开数据库
OleDbCommand cmd;
cmd=new OleDbCommand("select count(*) from t_system_person where per_name='" + per_name.Text + "'", conn);
int a= Convert.ToInt32(cmd.ExecuteScalar());//第一行第一列 既是查到的count值
if (a == 1)
{
Response.Write("用户重复");
}
else
{
cmd = new OleDbCommand("Insert Into t_system_person(per_id,per_name,pwd) Values('" + per_id.Text + "','" + per_name.Text + "','" + pwd.Text + "')", conn);
cmd.ExecuteNonQuery();//执行操作,插入记录
Response.Write("添加成功");
}
conn.Close(); //关闭数据库
Response.Redirect("user_add.aspx");
}
</script> 展开
void Enter_click(Object Sender, EventArgs E)
{
//建立Connection对象
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/database/data.mdb"));
//建立Command对象
conn.Open(); //打开数据库
OleDbCommand cmd;
cmd=new OleDbCommand("select count(*) from t_system_person where per_name='" + per_name.Text + "'", conn);
int a= Convert.ToInt32(cmd.ExecuteScalar());//第一行第一列 既是查到的count值
if (a == 1)
{
Response.Write("用户重复");
}
else
{
cmd = new OleDbCommand("Insert Into t_system_person(per_id,per_name,pwd) Values('" + per_id.Text + "','" + per_name.Text + "','" + pwd.Text + "')", conn);
cmd.ExecuteNonQuery();//执行操作,插入记录
Response.Write("添加成功");
}
conn.Close(); //关闭数据库
Response.Redirect("user_add.aspx");
}
</script> 展开
展开全部
你都Response.Redirect了,用这个吧
Response.Write(GetJSStr("添加成功"));
public string GetJSStr(string jsStr)
{
return @"<script type=""text/javascript"">
alert('" + jsStr + @"');
</script>";
}
更多追问追答
追答
1、js最好用单引号('):alert('用户重复');
2、要么前面加@,两个双引号("")代表一个双引号:@"";
3、要么就用+号连接,c#里面没有\" 这个转义符:"";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询