Jump to content

A Code that opens access database

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
elizabethmwashuma

elizabethmwashuma

    Newbie

  • Members
  • PipPip
  • 29 posts
hi everyone,

i need help....i want a code that connects to a database and directly opens the database...

thanks in advance.

regards.

#2
BuckAMayzing

BuckAMayzing

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
at the top you need to have:
using System.Data.ODBC;

then you can use SQL-like method to connect to the database. For an example, let's say you have a windows form with a DataGridView control called "dgvTable" in it:

OdbcConnection conn = new OdbcConnection("YOUR CONNECTION STRING GOES HERE. GOOGLE "ACCESS CONNECTION STRING" TO FIND IT");
OdbcQuery query = conn.CreateCommand();
query.CommandText = "select COLUMN1,COLUMN2,COLUMN3 from TABLE1 where COLUMN1 = 'someval'"; 
Dataset ds = new DataSet();
OdbcDataAdpater adapter = new OdbcDataAdapter(query);
adapter.Fill(ds);
dgvTable.DataSource = ds.Tables[0];

Of course, there are TONS of ways to do this, and this is a very simple example. But as far as I know, access supports basic SQL syntax.

#3
elizabethmwashuma

elizabethmwashuma

    Newbie

  • Members
  • PipPip
  • 29 posts
what is the main difference btween odbc and oledb.....i tried the code you gave me....has got errors

#4
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
Some searching wouldn't hurt anyone: http://forum.codecal...p-access-c.html
This thread was posted less then a week ago.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#5
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
Some searching wouldn't hurt anyone: http://forum.codecal...p-access-c.html
This thread was posted less then a week ago.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#6
BuckAMayzing

BuckAMayzing

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
I meant Oledb anyway. The code is the same, just replace Odbc with Oledb.