为什么insert的数据无法存进数据库?
public partial class studentmodify : System.Web.UI.Page{
string sno = "";
protected void Page_Load(object sender, EventArgs e)
{
sno = Request.QueryString["ID"].ToString(); //获取对图书操作的方式
if (!IsPostBack) //判断是否是首次加载
{
//自定义方法绑定书架
if (sno != "add") //判断是否是添加操作
{
this.Title = "修改学生信息";
txtSex.ReadOnly = true;
string sql = "select * from student where sno='" + sno + "'"; //调用自定义方法生成条形码
SqlDataReader sdr = dataOperate.getRow(sql);
sdr.Read();
txtSno.Text = sdr["sno"].ToString();
txtSname.Text = sdr["sname"].ToString();
txtSex.Text = sdr["易做图"].ToString();
txtSage.Text = sdr["age"].ToString();
txtSmajor.Text = sdr["major"].ToString();
txtSclass.Text = sdr["class"].ToString();
sdr.Close();
}
else
{
this.Title = "添加学生信息";
getSno();
}
}
}
public void getSno() //生成学生学号
{
string sql = "select max(sno)+1 as newsno from student ";
SqlDataReader sdr = dataOperate.getRow(sql);
sdr.Read();
string newsno = sdr["newsno"].ToString();
txtSno.Text = newsno;
}
protected void btnSave_Click(object sender, EventArgs e)
{
string sno = txtSno.Text;
string sname = txtSname.Text;
string 易做图= txtSex.Text ;
string age = txtSage.Text;
string major = txtSmajor.Text;
string sclass= txtSclass.Text;
string sql = "";
if (sno != "add")
{
sql = "update student set sname='" + sname + "',age='" + age + "',major='" + major + "',class='" + sclass + "' where sno='" + sno + "'";
}
else //sql = "insert into student (sno,sname,易做图,age,major,class) values ('" +sno + "','" + sname + "','" + 易做图 + "'," + age + ",'" + major + "','" + sclass + "')";
sql = string.Format("insert into student (sno,sname,易做图,age,major,class) values('{0}','{1}','{2}','{3}','{4}','{5}')", sno, sname, 易做图, age, major, sclass);
if (dataOperate.execSQL(sql)) //判断添加或修改是否成功
{
Response.Write("<script language=javascript>alert('保存成功!');window.opener.location.href=window.opener.location='studentmanage.aspx';window.close();</script>");
}
else
{
RegisterStartupScript("", "<script>alert('保存失败!')</script>");
}
}
protected void txtSname_TextChanged(object sender, EventArgs e)
{
string a = txtSname.Text;
Label1.Text = a;
}
}
--------------------编程问答-------------------- 单步跟踪sql 在查询分析器执行看看
一般使用SqlParameter
--------------------编程问答-------------------- 单步跟踪下 --------------------编程问答-------------------- 看看你这个表的字段类型吧 估计是非varchar 类型 你给加上了' ' 所以会出现问题 最好单步跟踪下 检查下SQL语句 另外可以在数据里手动执行一遍这个sql 语句 看能不能成功 --------------------编程问答-------------------- 报什么错误? --------------------编程问答-------------------- 就是显示保存成功,可是没有易做图数据库 --------------------编程问答-------------------- sno,sname,class,major 是 varchar
age 是int
易做图 是nchar
补充:.NET技术 , ASP.NET