首页 > 代码库 > 数据库连接备忘
数据库连接备忘
1.Access2007
using System.Data.OleDb;
using System.IO;
using System.Diagnostics;
string dataFile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)+"\\CustomaryOrder.accdb"; private void btnLogin_Click(object sender, EventArgs e) { //string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "CustomaryOrder.accdb;Persist Security Info=True"; //连接数据库 OleDbConnection con = new OleDbConnection(); //Access 2007 con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Jet OLEDB:Database Password=123456;Data Source="+dataFile+""; con.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandText = "select * from Login";//1是表名 OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string str=reader.GetValue(1).ToString(); } reader.Close(); con.Close(); panelLogin.Hide(); FrmCustomaryOrder myFrm = new FrmCustomaryOrder(); myFrm.MdiParent= this; myFrm.WindowState = FormWindowState.Maximized; myFrm.Show(); }
数据库连接备忘
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。