Insert 语句错误
publicpartialclassmode_register:System.Web.UI.UserControl{protectedvoidPage_Load(obje...
public partial class mode_register : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/db1.mdb");
string insertsql = "insert into username(name,password,company,email) values(@name,@pwd,@cpy,@eml)";
string str = "select count(*) from username where name='" + this.name.Text.Trim() + "'";
OleDbCommand comm = new OleDbCommand(str, conn);
conn.Open();
int N = (int)comm.ExecuteScalar();
if (N == 0)
{
comm.CommandText = insertsql;
comm.Parameters.Add(new OleDbParameter("@name",OleDbType.VarChar,50));
comm.Parameters["@name"].Value = name.Text.ToString().Trim();
comm.Parameters.Add(new OleDbParameter("@pwd", OleDbType.VarChar,50));
comm.Parameters["@pwd"].Value = pwd.Text.ToString().Trim();
comm.Parameters.Add(new OleDbParameter("@cpy", OleDbType.VarChar,50));
comm.Parameters["@cpy"].Value = cpy.Text.ToString().Trim();
comm.Parameters.Add(new OleDbParameter("@eml", OleDbType.VarChar,50));
comm.Parameters["@eml"].Value = eml.Text.ToString().Trim();
comm.ExecuteNonQuery();
Label1.Text = "注册成功";
}
else
{
Label1.Text = "该用户名已被注册";
}
conn.Close();
}
}
以上是用VS2005做的注册功能,显示insert语句错误,求高手帮忙!!! 展开
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/db1.mdb");
string insertsql = "insert into username(name,password,company,email) values(@name,@pwd,@cpy,@eml)";
string str = "select count(*) from username where name='" + this.name.Text.Trim() + "'";
OleDbCommand comm = new OleDbCommand(str, conn);
conn.Open();
int N = (int)comm.ExecuteScalar();
if (N == 0)
{
comm.CommandText = insertsql;
comm.Parameters.Add(new OleDbParameter("@name",OleDbType.VarChar,50));
comm.Parameters["@name"].Value = name.Text.ToString().Trim();
comm.Parameters.Add(new OleDbParameter("@pwd", OleDbType.VarChar,50));
comm.Parameters["@pwd"].Value = pwd.Text.ToString().Trim();
comm.Parameters.Add(new OleDbParameter("@cpy", OleDbType.VarChar,50));
comm.Parameters["@cpy"].Value = cpy.Text.ToString().Trim();
comm.Parameters.Add(new OleDbParameter("@eml", OleDbType.VarChar,50));
comm.Parameters["@eml"].Value = eml.Text.ToString().Trim();
comm.ExecuteNonQuery();
Label1.Text = "注册成功";
}
else
{
Label1.Text = "该用户名已被注册";
}
conn.Close();
}
}
以上是用VS2005做的注册功能,显示insert语句错误,求高手帮忙!!! 展开
2个回答
展开全部
string insertsql = "insert into username(name,[password],company,email) values('"+@name+"','皮纳"+@pwd+"陪模','"+@cpy+"','"+@eml+"')"; 或者芦握缓
string insertsql = "insert into username(name,[password],company,email) values(@name,@pwd,@cpy,@eml)";
string insertsql = "insert into username(name,[password],company,email) values(@name,@pwd,@cpy,@eml)";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询