asp.net中如何把添加的信息自动存到数据库中?
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class gg_add : System.Web.UI.Page
{
public string lb,lbtxt,sql;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
lb = Request.QueryString["lb"].ToString().Trim();
switch (lb)
{
case "1":
lbtxt = "站内新闻";
break;
case "2":
lbtxt = "教育资讯";
break;
}
sql = "insert into allgonggao(title,content,leibie) values('" + title.Text.ToString().Trim() + "','" + WebEditor1.Text + "','" + lbtxt + "')";
int result;
result = new Class1().hsgexucute(sql);
if (result == 1)
{
Response.Write("<script>javascript:alert('添加成功');</script>"); //如果执行成功,则给出提示
}
else
{
Response.Write("<script>javascript:alert('系统错误');</script>");
}
}
}
运行后不成功
--------------------编程问答-------------------- 先保证你的sql语易做图确,然后自己跟踪new Class1().hsgexucute中干了什么 --------------------编程问答-------------------- 调试把sql语句拿到数据库中执行一下,没错的话看看result = new Class1().hsgexucute(sql);hsgexucute是不是正确执行? --------------------编程问答--------------------
.... --------------------编程问答-------------------- protected void Page_Load(object sender, EventArgs e)
{
if(!ispostback)//加上这个再试试
{}
}
补充:.NET技术 , ASP.NET