using System.Collections.Generic; using System.Linq; using System.Text;
using System.Data.OleDb;
namespace DataConnnction.Dataconn {
class AccessConnction {
// //构造连接字符串
// string strConnection=\"Provider=Microsoft.Jet.OleDb.4.0;\";
//strConnection +=@\"Data Source=//192.168.1.10//access//CSharptest.mdb\"; //连接2003
//string ACCESS_CONN_STRING = \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\" + strPath.ToString() + \";User Id=admin;Password=;\";
//连接2007
private static string strConnect = \"Provider = Microsoft.ACE.OLEDB.12.0;Data Source = \" + System.Environment.CurrentDirectory + \"\\\\MY.accdb\" + \";User Id=admin;Password=;\"; //Application.StartupPath + \"\\\\MY.MDB\";
public string AccConnction() {
string ret = null;
OleDbConnection conConnection = new OleDbConnection(strConnect); try {
conConnection.Open(); ret = \"true\"; return ret; } catch {
ret = \"false\"; return ret; }
finally {
conConnection.Close(); conConnection.Dispose(); }
//return ret;
}
} }
因篇幅问题不能全部显示,请点此查看更多更全内容