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.Common;
using System.Data.OleDb;public partial class admin_BBS : System.Web.UI.Page
{
string userid;
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
/* TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = ""; */
}
protected void Button3_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string yh=TextBox3.Text.ToString();
string mm=TextBox4.Text.ToString();
string yx=TextBox5.Text.ToString();
string oledb = string.Format("insert into userInfo(username,password,email) values('" + yh + "','" + mm + "','" + yx + "')");
this.ExcuteOledb(oledb);
messageLabel.Text = "注册成功!";
Panel1.Visible = true;
LinkButton3.Visible = true;
}
}
private void ExcuteOledb(string strOledb)
{
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/#data.mdb");
DbProviderFactory dbFactory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection dbConn = dbFactory.CreateConnection();
dbConn.ConnectionString = strConn;
dbConn.Open();
DbCommand dbComm = dbFactory.CreateCommand();
dbComm.Connection = dbConn;
dbComm.CommandText = strOledb;
dbComm.ExecuteNonQuery();
dbConn.Close();
dbConn.Dispose();
}
protected void Button4_Click(object sender, EventArgs e)
{
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("BBS.aspx");
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
DL_Panel1.Visible = false;
ZT_Panel2.Visible = true;
}
protected void Button5_Click(object sender, EventArgs e)
{
DL_Panel1.Visible = false;
ZT_Panel2.Visible = false;
ZC_Panel3.Visible = true;
}
protected void Button6_Click(object sender, EventArgs e)
{
Response.Redirect("BBS.aspx");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
DL_Panel1.Visible = true;
ZC_Panel3.Visible = false;
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Response.Redirect("BBS.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid) {
string sConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/#data.mdb");
DbProviderFactory sdbConn = DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection tConn = sdbConn.CreateConnection();
tConn.ConnectionString = sConn;
tConn.Open();
DbCommand tComm = sdbConn.CreateCommand();
tComm.Connection = tConn;
tComm.CommandText = "Select id,password from userInfo where username='"+TextBox1.Text+"'";
IDataReader readr = tComm.ExecuteReader();
try {
if (readr.Read())
{
if (readr.GetString(1) == TextBox2.Text)
{
userid = readr.GetInt32(0).ToString();
Session["userid"] = userid;
Response.Redirect("BBSdis.aspx");
}
else
{
Panel1.Visible = true;
Label1.Text = "没有这个用户";
}
}
else
{
Panel1.Visible = true;
Label1.Text = "没有这个用户";
}
}
finally
{
readr.Close();
tConn.Close();
tConn.Dispose();
}
}
}
}
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.Common;
using System.Data.OleDb;public partial class admin_BBS : System.Web.UI.Page
{
string userid;
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
/* TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = ""; */
}
protected void Button3_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string yh=TextBox3.Text.ToString();
string mm=TextBox4.Text.ToString();
string yx=TextBox5.Text.ToString();
string oledb = string.Format("insert into userInfo(username,password,email) values('" + yh + "','" + mm + "','" + yx + "')");
this.ExcuteOledb(oledb);
messageLabel.Text = "注册成功!";
Panel1.Visible = true;
LinkButton3.Visible = true;
}
}
private void ExcuteOledb(string strOledb)
{
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/#data.mdb");
DbProviderFactory dbFactory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection dbConn = dbFactory.CreateConnection();
dbConn.ConnectionString = strConn;
dbConn.Open();
DbCommand dbComm = dbFactory.CreateCommand();
dbComm.Connection = dbConn;
dbComm.CommandText = strOledb;
dbComm.ExecuteNonQuery();
dbConn.Close();
dbConn.Dispose();
}
protected void Button4_Click(object sender, EventArgs e)
{
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("BBS.aspx");
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
DL_Panel1.Visible = false;
ZT_Panel2.Visible = true;
}
protected void Button5_Click(object sender, EventArgs e)
{
DL_Panel1.Visible = false;
ZT_Panel2.Visible = false;
ZC_Panel3.Visible = true;
}
protected void Button6_Click(object sender, EventArgs e)
{
Response.Redirect("BBS.aspx");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
DL_Panel1.Visible = true;
ZC_Panel3.Visible = false;
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Response.Redirect("BBS.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid) {
string sConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/#data.mdb");
DbProviderFactory sdbConn = DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection tConn = sdbConn.CreateConnection();
tConn.ConnectionString = sConn;
tConn.Open();
DbCommand tComm = sdbConn.CreateCommand();
tComm.Connection = tConn;
tComm.CommandText = "Select id,password from userInfo where username='"+TextBox1.Text+"'";
IDataReader readr = tComm.ExecuteReader();
try {
if (readr.Read())
{
if (readr.GetString(1) == TextBox2.Text)
{
userid = readr.GetInt32(0).ToString();
Session["userid"] = userid;
Response.Redirect("BBSdis.aspx");
}
else
{
Panel1.Visible = true;
Label1.Text = "没有这个用户";
}
}
else
{
Panel1.Visible = true;
Label1.Text = "没有这个用户";
}
}
finally
{
readr.Close();
tConn.Close();
tConn.Dispose();
}
}
}
}
这里报
用户代码未处理OleDbException INSERT INTO 语句的语法错误。
这个是命令类型,是指cmdText还是存储过程,应改为CommandType.cmdText
这个是命令类型,是指cmdText还是存储过程,应改为CommandType.cmdText
在构造command命令时可以把你的查询语句传进去,而不是写在这里
这个是命令类型,是指cmdText还是存储过程,应改为CommandType.cmdText
在构造command命令时可以把你的查询语句传进去,而不是写在这里
DbCommand dbComm = dbFactory.CreateCommand(); 构造dbcomm的时候把查询语句和连接传进去就行了
dbComm.CommandText = strOledb; 这句有问题
这个是命令类型,是指cmdText还是存储过程,应改为CommandType.cmdText
在构造command命令时可以把你的查询语句传进去,而不是写在这里
能不能给个修改完全的代码啊
我改成你写的浏览不了了
dbComm.CommandText = strOledb; 这句有问题
这个是命令类型,是指cmdText还是存储过程,应改为CommandType.cmdText
在构造command命令时可以把你的查询语句传进去,而不是写在这里
能不能给个修改完全的代码啊
我改成你写的浏览不了了