首页 > 代码库 > 数据库连接备忘

数据库连接备忘

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();        }

 

数据库连接备忘