读书人

关于数据库连接烦恼

发布时间: 2012-06-07 15:05:14 作者: rapoo

在线等,关于数据库连接,烦恼。
public static string conntion()
{


string strCon1 = "Data Source =" + System.Web.HttpContext.Current.Server.MapPath("aa.accdb");
string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=false;" + strCon1;


return strCon;
}

public****()
{
OleDbCommand con = db.conntion;----------------------》》这里出错。说是类型不一致,我的conntion返回的是string类型。
con.open();

}

如果我吧返回类型变了,变成OleDbConnection,可是也不行,因为我需要return strCon;这里的strcon是string类型。除非还有别的连接数据库的方法能做到不是string类型,

求救啊。

[解决办法]

OleDbConnection connect = new OleDbConnection(conntion());//连接access数据库
connect.Open();
OleDbCommand command = new OleDbCommand(sql, connect);//执行sql命令

读书人网 >asp.net

热点推荐