ACCESS数据库转换为SQL2005后,数据库链接代码怎么改?
privatestaticOleDbConnectionConnection{//连接对象的属性get{stringstrCN="Provider=Microsoft.J...
private static OleDbConnection Connection
{//连接对象的属性
get
{
string strCN = "Provider=Microsoft.Jet.OLEDB.4.0;jet OleDB:Database Password=XuGuangYuan;Data Source=" + FilePath.strFileDir + @"Data\DBLC.mdb";
if (conn == null)
{
conn = new OleDbConnection(strCN);
conn.Open();
}
else if (conn.State == ConnectionState.Closed)
conn.Open();
else if (conn.State == ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
}
//不带参数的执行命令
public static int ExecuteCommand(string safeSql)
{
OleDbCommand cmd = new OleDbCommand(safeSql, Connection);
int result = (int)cmd.ExecuteNonQuery();
return result;
Connection.Close();
}
//带参数的执行命令
public static int ExecuteCommand(string Sql, params OleDbParameter[] values)
{
OleDbCommand cmd = new OleDbCommand(Sql, Connection);
cmd.Parameters.AddRange(values);
return (int)cmd.ExecuteNonQuery();
Connection.Close();
} 展开
{//连接对象的属性
get
{
string strCN = "Provider=Microsoft.Jet.OLEDB.4.0;jet OleDB:Database Password=XuGuangYuan;Data Source=" + FilePath.strFileDir + @"Data\DBLC.mdb";
if (conn == null)
{
conn = new OleDbConnection(strCN);
conn.Open();
}
else if (conn.State == ConnectionState.Closed)
conn.Open();
else if (conn.State == ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
}
//不带参数的执行命令
public static int ExecuteCommand(string safeSql)
{
OleDbCommand cmd = new OleDbCommand(safeSql, Connection);
int result = (int)cmd.ExecuteNonQuery();
return result;
Connection.Close();
}
//带参数的执行命令
public static int ExecuteCommand(string Sql, params OleDbParameter[] values)
{
OleDbCommand cmd = new OleDbCommand(Sql, Connection);
cmd.Parameters.AddRange(values);
return (int)cmd.ExecuteNonQuery();
Connection.Close();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询