数据库连接备忘
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(); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。