数据库添加,有错误,不知道在哪?
看看我的错误在哪?找不着,添加不进去数据using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text;
namespace Article.Web
{
public partial class WebForm1 : System.Web.UI.Page
{
string strname =null;
string straddress = null;
string strphone = null;
string stremail = null;
string strgroupid = null;
protected void Page_Load(object sender, EventArgs e)
{
InitRequestParams();
}
private void InitRequestParams()
{
this.strname = Request.Form["txtName"];
this.straddress = Request.Form["txtAddress"];
this.strphone = Request.Form["txtPhone"];
this.stremail = Request.Form["txtEmail"];
//this.strgroupid = Request.Form["select"];
}
**************************************************************************这上部分应该没有问题*************
protected void Button1_Click(object sender, EventArgs e)
{
if (!strname.Equals(""))
{
add();
}
else
{
Response.Write("<script language=javascript>alert('用户名不能为空');</" + "script>");
}
}
private void add()
{
SqlConnection con = new SqlConnection("server=.;database=test;uid=sa;pwd=server");
con.Open();
try
{
SqlCommand cn = new SqlCommand("insert into Staff (Name,Address,Phone,Email) values('" + strname + "','" + straddress + "','" + strphone + "','" + stremail + "')", con);
cn.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('添加成功');</" + "script>");
}
catch (Exception ex) {
Response.Write("<script language=javascript>alert('添加失败');</" + "script>");
}
}
}
}
大家帮我看看啊