Solved

C# read MS Access database

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

17 Experts available now in Live!

Get 1:1 Help Now