Solved

C# read MS Access database

Posted on 2010-11-24
4
646 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

829 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