Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# read MS Access database

Posted on 2010-11-24
4
Medium Priority
?
656 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 30

Accepted Solution

by:
anarki_jimbel earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

597 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