请教各位大侠:asp.net使用c#如何操作access数据库
我做了个留言簿,使用sql server2000数据库,调试通过,但我想改成access数据库,但总是出错,后来我做了个简单的注册、登陆、修改资料的程序,使用access数据库,注册写入数据库正常、登陆查询数据库也正常,但修改数据库就提示错误,不知道是不是语句用得不对,还是有些地方(如数据库的安全、数据库源)设置的问题。请教大侠,谢谢指点!
附源程序:
注册
private void Button2_Click(object sender, System.EventArgs e)
{
OleDbConnection Myconn=new OleDbConnection((string)Application["OleDbConnectionString"]);
string strIns="Insert Into aduser (adpwd,adphone,ademail,adweb,adqq,adname,adrname) Values('"+this.TBconfirm.Text+"','"+this.TBphone.Text+"','"+this.TBemail.Text+"','"+this.TBweb.Text+"','"+this.TBqq.Text+"','"+this.TBname.Text+"','"+this.TBrname.Text+"')";
OleDbCommand mycmd=new OleDbCommand(strIns,Myconn);
Myconn.Open();
try
{
mycmd.ExecuteNonQuery();
Response.Write("成功操作数据库");
}
catch
{
Response.Write("写入数据库出错");
}
finally
{
Myconn.Close();
Response.Redirect("login.aspx");
}
}
登陆:
private void Button1_Click(object sender, System.EventArgs e)
{
OleDbConnection Myconn=new OleDbConnection((string)Application["OleDbConnectionString"]);
string strsel="select adminid from aduser where adname='"+this.adminuser.Text+"'and adpwd='"+this.password.Text+"'";
OleDbCommand cmd = new OleDbCommand(strsel,Myconn);
Myconn.Open();
OleDbDataReader reader=cmd.ExecuteReader();
if(reader.Read())
{
Session["userid"]=reader["adminid"].ToString();
Session["user"]="管理员";
reader.Close();
Myconn.Close();
Response.Redirect("change.aspx");
}
else
{
Label1.Text="输入管理员密码不正确";
Label1.Visible=true;
reader.Close();
Myconn.Close();
}
}
修改资料:
private void Button2_Click(object sender, System.EventArgs e)
{
OleDbConnection Myconn=new OleDbConnection((string)Application["OleDbConnectionString"]);
string strUpdate="Update aduser set adpwd='"+ this.TBconfirm.Text +"',adphone='"+ this.TBphone.Text +"',ademail='"+this.TBemail.Text+"',adweb='"+this.TBweb.Text+"',adqq='"+this.TBqq.Text+"',adname='"+this.TBname.Text+"',adrname='"+this.TBrname.Text+"' Where adminid='"+Session["userid"].ToString()+"'";
Myconn.Open();
OleDbCommand Mycomm=new OleDbCommand(strUpdate,Myconn);
try
{
Mycomm.ExecuteNonQuery();
Response.Write("成功操作数据库");
}
catch
{
Response.Write(Myconn.ConnectionString + "更新数据库失败....<BR>");
}
finally
{
Mycomm.Dispose();
Myconn.Close();
}
}