当前位置:Gxlcms > 数据库问题 > c#.net连接access数据库

c#.net连接access数据库

时间:2021-07-01 10:21:17 帮助过:2人阅读

c#.net连接access数据库

前期工作:创建一个access数据库,名为yonghu.mdb ,表明yonghu,字段为user_id,user_pwd PS:如何新建access数据库:左上角菜单按钮->新建-》点右下角起名字文件夹(保存类型选2002-2003数据库)-》(yonghu)确定-》打开access-》左上角试图按钮-》设计试图-》起表名字(yonghu)-》字段填user_id类型文本,字段user_pwd类型文本-》切换到数据表试图,天上数据—》关闭access OK!数据库建完! vs2008中新建网站-》asp.net网站,用控件制作个登录界面, 技术分享 -》控件名txtyh,txtpwd,btnok,btnqx 登录按钮事件->using System.Data.OleDb;填包 public partial class datalogin : System.Web.UI.Page
{
    OleDbConnection con = new OleDbConnection();
    OleDbCommand cmd = new OleDbCommand();
    OleDbDataAdapter oda = new OleDbDataAdapter();
    DataSet ds = new DataSet();
    DataTable dta = new DataTable();
    protected void Page_Load(object sender, EventArgs e)     //定义 } 单击按钮事件代码 //Server.MapPath是你的数据库的地址,我把他放到该项目的app_data目录下 con.ConnetctionString="provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("app_data/yonghu.mdb"); con.Open(); cmd.Connection=con; cmd.CommandText="select * from yonghu where user_id=‘"+txtyh.Text+"‘and user_pwd=‘"+txtpwd.Text+"‘"; oda=new OleDbDataAdapter(cmd); oda.Fill(ds,"yonghu"); if(ds.Tables[0].Rows.Count==0) {  Response.Write("<script>alert(‘用户姓名或者密码错误!!‘)</script>"); } else { Response.Redirect("OK.aspx"); }     新建ok.aspx;如果成功就跳转过去了 别忘了配置odbc数据源哦,亲 来源地址:http://blog.csdn.net/zaifeishandong/article/details/7372870

c#.net连接access数据库

标签:

人气教程排行