我正在使用以下代码连接到Access 2007数据库:
public void RetrieveData(){
OleDbConnection conn=null;
OleDbDataReader reader=null;
string strConnection= @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\PC\\Documents\\School.accdb;Persist Security Info=False;";
try
{
conn = new OleDbConnection(strConnection);
conn.Open();
OleDbCommand cmd = new OleDbCommand("select * from Class", conn);
reader = cmd.ExecuteReader();
DataList1.DataSource = reader;
DataList1.DataBind();
}
catch (Exception e)
{
Response.Write(e.Message);
Response.End();
}
finally
{
if (reader != null) reader.Close();
if (conn != null) conn.Close();
}
}
但是当我运行它时,它只会给出一个空白页面。在调试模式下,我可以看到 conn 的数据库属性为空 "",这可能是什么问题?