Im using this code to connect to access 2007 database :
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();
}
}
but when i run it it jus give blank page.in debug mode I can see that the database property of conn is empty "" what would it be the problem?
in the web.config
<connectionStrings>
<!-- connection string declared for connecting the web application with MS Access 2007 -->
<!-- connection string for MS Access 2007 accdb file -->
<add name="AccessConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.accdb;Persist Security Info=False;Jet OLEDB:Database Password=;" providerName="System.Data.OleDb" />
</connectionStrings>
and from the code behind use this
import namespaces
using system.data.oledb;
// to access the connection string stored in the web.config file.
OleDbConnection myDataConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
reply if it is useful or not
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With