Hi,
I want to display data from MS Access into gridview control.
but i am getting unhandeled exception in connection string that is 'Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\shreedharmanagementsystem\shreedharmanagementsystem\App_Data\my.accdb' is not a valid virtual path.
Code is given below .
string connection = "Data Source=C:\\Documents and Settings\\Administrator\\My Documents\\my.accdb";
string query= "Select * from fee where status=Pending ";
AccessDataSource ads = new AccessDataSource(connection,query);
GridView1.DataSource = ads;
GridView1.DataSourceID = String.Empty;
GridView1.DataBind();
Pls help me out
Thanks&Regards
Abhishek
Loading
Suthish NairPosted Mar 27, 2011, 11:36 AM
Find Database Connection and Generate Connection String using Visual Studio
VulpesPosted Mar 27, 2011, 9:15 AM
Soft CornerPosted Mar 27, 2011, 8:48 AM
unrecognized database format '.accdb' error occur when Provider name is wrong. so i guess you are using access 2007, change your provider as :
Provider=Microsoft.ACE.OLEDB.12.0
abhishek tiwariPosted Mar 27, 2011, 6:47 AM
I have modify my source code as u told and also have been installed Data Connectivity Components but now i am getting exception
Unrecognized database format 'C:\Documents and Settings\Administrator\My Documents\my.accdb'.
Pls Help Me.
Abhishek
VulpesPosted Mar 27, 2011, 6:00 AM
Soft CornerPosted Mar 27, 2011, 5:56 AM
In ASP.Net, there is a default directory App_Data to store the database files. You can store the MS Access database file inside the App_Data directory that can be useful for providing its relative path in the connection string for Access Database.
then try this :
string connection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|my.accdb providerName=System.Data.OleDb";
|DataDirectory| is used in the above of connection string to connect the MS Access Database placed inside the App_Data directory. By Default |DataDirectory| maps the path of database file placed inside the default App_Data directory.