Solved

C# read MS Access database

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now