Groups > Databases > Access Databases and AccessDataSource Control > Re: ASP.Net Access Help




ASP.Net Access Help

ASP.Net Access Help
Sat, 29 Mar 2008 15:37:41 +000
hi all! 

im building a website and i tried using an accesss DB but i have 2 main problems
with it!
1. when i try to create the connection using: new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=db.mdb"); (in a c# code page) the debuger says he cannot find the
file in the system32 folder. and the same goes if i try using Data
Source=http://localhost/db.mdb. do anyone knows what it could be? and how can i
solve it?

2. how can i create a query using parameters? like a value of an input box.
Post Reply
Re: ASP.Net Access Help
Sat, 29 Mar 2008 16:44:10 +000
#1) in your connection string, use the full windows path to the database.

 

#2) OleDbCommand cmd = new OleDbCommand("SELECT name FROM Category WHERE
CategoryID = ?");
cmd.Parameters.AddWithValue("CategoryID", txtInput.Text);

I think the ? would work for access.  If not, resort to @CategtoryID for it and
the parameter value.
Post Reply
Re: ASP.Net Access Help
Sat, 29 Mar 2008 17:27:59 +000
The easiest way to manage the path to the database is to put the database file
into the App_Data folder in your web site, then your connection string is
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|db.mdb".

|DataDirectory| is resolved by ASP.NET to find the App_Datafolderr.

With regard to parameters, Access and ASP.NET, this should help:
http://www.mikesdotnetting.com/Article.aspx?ArticleID=26
Post Reply
about | contact