Link to home
Create AccountLog in
Avatar of Denisdh
DenisdhFlag for Ireland

asked on

How to access MS Access Database in C#/ASP.Net

I need to access a table in a *.mdb file in a aspx/C# web service and make some calculations and then display it. I'm looking for a tutorial but haven't found anything online.
Avatar of Haris V
Haris V
Flag of India image


importing the namespace System.Data.Odbc 

example for grid binding

 Dim cn As New OdbcConnection("Driver={Microsoft Access
Driver (*.mdb)};DBQ=c:\AccessDB\MyDB.mdb")
        Dim da As New OdbcDataAdapter("select * from emp", cn)
        Dim dt As New DataTable
        da.Fill(dt)
        da.Dispose()
        cn.Dispose()
        Me.DataGrid1.DataSource = dt
        Me.DataGrid1.DataBind()
this is password protected ms access DB

Dim cn As New OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\AccessDB\MyDBwithPwd.mdb;User Id=admin;Jet
OLEDB:Database Password=admin")
ASKER CERTIFIED SOLUTION
Avatar of Haris V
Haris V
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Denisdh

ASKER

That code is VB. Is it much different in C#?
Avatar of Denisdh

ASKER

Thanks for the pointers guys. Ignore the last comment I only saw the first post when I wrote it. I'll head off and do some learning!
Avatar of Denisdh

ASKER

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/reports.mdb"
SelectCommand="SELECT [Agent], [County] FROM [tblWebData]"></asp:AccessDataSource>
asp:AccessDataSource can be found in the toolbox of VWD and it works fine.