2 Replies - 7594 Views - Last Post: 29 May 2009 - 09:44 AM Rate Topic: -----

#1 Yoonsi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-May 09

Visual studio, connecting to an access database (C#)

Posted 29 May 2009 - 08:55 AM

Hi everyone,

First post. I'm taking a course in applications programming in C#. I'm going over trying to connect my application to a Microsoft access database. I've added the data source, I've created (OleDBconnection, and dragged it onto the form) and set the connection.
When I drag a dataGridView onto the form, and run the code, it stays blank. What have I missed? (from what I'm reading, the dataGridView should get populated.)

Any help would be appreciated. Also, if anyone could link me to a site that has tutorials on working with access databases with visual studio (ADO.NET, C#)

Many thanks,
-Yoonsi

Is This A Good Question/Topic? 0
  • +

Replies To: Visual studio, connecting to an access database (C#)

#2 karimi  Icon User is offline

  • Banned
  • member icon

Reputation: -9
  • View blog
  • Posts: 104
  • Joined: 29-May 09

Re: Visual studio, connecting to an access database (C#)

Posted 29 May 2009 - 09:41 AM

Ater setting the required properties of the follwing do the following:

1) Drag and draw OledbDataset and set necssary properties like connection, and also the sql query.

2) set the datagrids dtatsource property tho this dataset and run the project.

U can accomplish such task in code to, follow these steps:

1) Add System.data.Oledb namespace;
2) Create aconnection object ast

Quote

Oledbconnection Con=new Oledbconnection("Write ur connection string here");


1) call the Open method of connection object as

Quote

Con.open();

2) Create a dataset object as
Dataset dst=new Dataset("tbl1");


3) Create A Dtata Adpater Objects with the sql query as first argument and connection as second argument in the constructor:
OledbAdpater adp=new Oledbadapeter("ur sql query",Con); 


4) Call the Adp.Fille(Dataset) Method to fill the dataset with the data retrived
adp.fill(dst);

and its done!

dtatagrid1.datasource=dst; //fills the grid

complete source:
Oledbconnection Con=new Oledbconnection("--your connection string here");
Con.open();
dtataset dst=new dataset("tbl");
oledbadapter adp= new oledbadapter("select query here",Con);
adp.fill(dst);
Con.close();
datagrid1.datasource=dst;

Was This Post Helpful? 1
  • +
  • -

#3 Yoonsi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-May 09

Re: Visual studio, connecting to an access database (C#)

Posted 29 May 2009 - 09:44 AM

First off, thank you very much for your reply.
However, I just tried what I was originally doing on my laptop and it worked... (I was originally working on my PC and it didn't work on that for some reason)
Both my PC and my laptop are running Vista (64 and 32 bit respectively)
Can anyone think of a reason why this would work on one and not the other?

Cheers!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1