简单INSERT语句插入数据库问题.
郁闷的要命,在其它页面这些语句正常运行,而这个就是插不进去,真的快疯了!代码如下:usingSystem;usingSystem.Data;usingSystem.Con...
郁闷的要命,在其它页面这些语句正常运行,而这个就是插不进去,真的快疯了!
代码如下:
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;
using System.Data.OleDb;
protected void Button1_Click(object sender, EventArgs e)
{
string t1 = TextBox1.Text.Trim();
string t2 = TextBox2.Text.Trim();
string dbpath = System.Configuration.ConfigurationSettings.AppSettings["dbpath"];
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=" + Server.MapPath(dbpath));
conn.Open();
string sle2 = "select * from tadmin where adminid='" + t1 + "'";
OleDbCommand cmd2 = new OleDbCommand(sle2, conn);
OleDbDataReader odb2 = cmd2.ExecuteReader();
if (odb2.Read())
{
Response.Write("<script>alert('此管理员已存在,请查询后重新输入!');history.go(-1);</script>");
TextBox1.Text = "";
conn.Close();
cmd2.Connection.Close();
Response.End();
}
else
{
//string ins = "insert into tadmin(adminid,password)values(\'" + t1 + "\',\'" + t2 + "\')"; //这句不行。
string ins="insert into tadmin (adminid,password) values (\'"+t1+"\',\'"+t2+"\')"; //这句也不行。
OleDbCommand comm = new OleDbCommand(ins, conn);
try
{
Response.Write(ins); //下有注释。
comm.ExecuteNonQuery();
Response.Write("<script>location.replace('../Defalult.aspx');</script>");
}
catch (OleDbException ex)
{
Response.Write("<script>alert('添加失败,请重试!(错误原因在页面顶端。)')</script>");
Response.Write(ex.Message);
}
conn.Close();
comm.Connection.Close();
comm.Dispose();
}
}
这是一个添加管理员的页面,当我在文本框中,输入管理员帐号为:12,密码为:12,就提示下面的错误:
insert into tadmin (adminid,password) values ('12','12')INSERT INTO 语句的语法错误。
上面的语句在其它页面可以正常插入,而这个就是不行。所以我就郁闷的快疯了。高手,帮忙啊!!!!
正在线呢,有意者HI我吧.解决了,可加高分!!!!!!!!!!!!!! 展开
代码如下:
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;
using System.Data.OleDb;
protected void Button1_Click(object sender, EventArgs e)
{
string t1 = TextBox1.Text.Trim();
string t2 = TextBox2.Text.Trim();
string dbpath = System.Configuration.ConfigurationSettings.AppSettings["dbpath"];
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=" + Server.MapPath(dbpath));
conn.Open();
string sle2 = "select * from tadmin where adminid='" + t1 + "'";
OleDbCommand cmd2 = new OleDbCommand(sle2, conn);
OleDbDataReader odb2 = cmd2.ExecuteReader();
if (odb2.Read())
{
Response.Write("<script>alert('此管理员已存在,请查询后重新输入!');history.go(-1);</script>");
TextBox1.Text = "";
conn.Close();
cmd2.Connection.Close();
Response.End();
}
else
{
//string ins = "insert into tadmin(adminid,password)values(\'" + t1 + "\',\'" + t2 + "\')"; //这句不行。
string ins="insert into tadmin (adminid,password) values (\'"+t1+"\',\'"+t2+"\')"; //这句也不行。
OleDbCommand comm = new OleDbCommand(ins, conn);
try
{
Response.Write(ins); //下有注释。
comm.ExecuteNonQuery();
Response.Write("<script>location.replace('../Defalult.aspx');</script>");
}
catch (OleDbException ex)
{
Response.Write("<script>alert('添加失败,请重试!(错误原因在页面顶端。)')</script>");
Response.Write(ex.Message);
}
conn.Close();
comm.Connection.Close();
comm.Dispose();
}
}
这是一个添加管理员的页面,当我在文本框中,输入管理员帐号为:12,密码为:12,就提示下面的错误:
insert into tadmin (adminid,password) values ('12','12')INSERT INTO 语句的语法错误。
上面的语句在其它页面可以正常插入,而这个就是不行。所以我就郁闷的快疯了。高手,帮忙啊!!!!
正在线呢,有意者HI我吧.解决了,可加高分!!!!!!!!!!!!!! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询