Solved

C# read MS Access database

Posted on 2010-11-24
4
644 Views
Last Modified: 2012-05-10
Hi. I am a newbie in .net ...
How do I make connection for my web site to access database: "c:\database.accdb"
And how do I read the columns: id, title, content ... I want to display data on page load and limit it to only one record at a time.
I would than filter the records using querystring from the URL.

Here is the code i have till now (of course empty ;) )
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{

    protected string title;
    protected string content;


    protected void Page_Load(object sender, EventArgs e)
    {


        // some code here


    }
}

Open in new window

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Title: <%=title %></h1>
        <p>Content: <%=content %></p>
    </div>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:kuzmar
  • 2
4 Comments
 
LVL 6

Expert Comment

by:AlfredRobot
ID: 34208796
this link shows you how to connect and read data(basic):
http://www.java2s.com/Tutorial/CSharp/0560__ADO.Net/ReaddatafromAccessdatabase.htm
0
 
LVL 6

Expert Comment

by:AlfredRobot
ID: 34208866
this one maybe better (though the extension is mdb instead of accdb)
http://www.c-sharpcorner.com/UploadFile/e628d9/3565/

good luck
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 34208883
Connection to an Access database not much different from other databases. The main thing is to provide proper connection string. First - it is proper provider, for Access it's OLEDB, Then, proper path tothe Access database (e.g., Northwind DB). So,  it's like:

string conString =
              @"Provider=Microsoft.JET.OLEDB.4.0;"
            + @"data source=c:\data\Northwind.mdb";
 
In your case you just need to provide a proper path to your specific database. That's all.

Just in case - some more links:

http://www.codeproject.com/KB/database/linkAccessInCSharp.aspx
http://en.csharp-online.net/Working_with_Data%E2%80%94Connecting_to_Access_using_OLE_DB 
0
 

Author Comment

by:kuzmar
ID: 34209014
Thanks... the last link was just what i was looking for.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question