469,356 Members | 1,930 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

SQL connection to Access database

Hi,

I wants to to something really simple, but dont succedd in C# :( I'm using
2005 beta version with .net 2 beta.

I wants to connect ot an Access database and do a query, and then in the
dataset a First() , Next() until Eof();

Also I want to access fields in the dataset (of course), but I cannot find
anything like 'fieldbyname' or something.. how access fiels ?

--
rgds, Wilfried
http://www.mestdagh.biz
Nov 16 '05 #1
7 18670
Found it :)

OleDbConnection Conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data
Source=C:\\test.mdb");
OleDbCommand SQL = new OleDbCommand("select * from Rx", Conn);
Conn.Open();
OleDbDataReader Reader = SQL.ExecuteReader();

int RXDT = Reader.GetOrdinal("RXDT");
int Sog = Reader.GetOrdinal("Sog");
while (Reader.Read()) {
Console.WriteLine(Reader.GetValue(Sog));
Console.WriteLine(Reader.GetValue(RXDT));
}
Reader.Close();
Conn.Close();

rgds, Wilfried
Nov 16 '05 #2
ADODB.ConnectionString=Provider=Microsoft.Jet.OLED B.4.0;User
ID=uzttkownik;Data Source=Scieszka_Plik;Mode=Share Deny None;Jet
OLEDB:Database Password=haslo;Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1

ADODB.Open() lub ADODB.Open("Provider=Microsoft.Jet.OLEDB.4.0;User
ID=uzttkownik;Data Source=Scieszka_Plik;Mode=Share Deny None;Jet
OLEDB:Database Password=haslo;Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1")

ADODB.Recordset.Open(sql,biezace_polaczenie(zwraca ne przez ADODB.Open),itd

if(!ADODB.Recordset.BOF) ADODB.Recordset.MoveNext();

if(!ADODB.Recordset.EOF) ADODB.Recordset.MoveFirst();

Adapter.Fill(DataSet, Recordset, NazwaTabeli)
Nov 16 '05 #3
ADODB.ConnectionString=Provider=Microsoft.Jet.OLED B.4.0;User
ID=user;Data Source=folder_file;Mode=Share Deny None;Jet
OLEDB:Database Password=password;Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1

ADODB.Open() or
ADODB.Open("ADODB.ConnectionString=Provider=Micros oft.Jet.OLEDB.4.0;User
ID=user;Data Source=folder_file;Mode=Share Deny None;Jet
OLEDB:Database Password=password;Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1")

ADODB.Recordset.Open(sql,current_connection(return by ADODB.Open),so

if(!ADODB.Recordset.BOF) ADODB.Recordset.MoveNext();

if(!ADODB.Recordset.EOF) ADODB.Recordset.MoveFirst();

Adapter.Fill(DataSet, Recordset, NazwaTabeli)
Nov 16 '05 #4
Hi Robert,

thanks but the compiler complains these members are not found in ADODB
namespce. Something I missing ?
Nov 16 '05 #5
you have to add references -> ADODB.dll from the solution Explorer
Nov 16 '05 #6
you have to add references -> ADODB.dll from the solution Explorer

private ADODB.Connection MDB = New ADODB.Connection();
private ADODB.Recordset Records = New ADODB.Recordset();
private OleDb.OleDbDataAdapter Adapter = New OleDb.OleDbDataAdapter();
priwate DataSet DS = new DataSet();

1. this.MDB.ConnectionString=Provider=Microsoft.Jet.O LEDB.4.0;User
ID=user;Data Source=folder_file;Mode=Share Deny None;Jet
OLEDB:Database Password=password;Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1

this.MDB.Open()

OR

2.
this.MDB.Open("ADODB.ConnectionString=Provider=Mic rosoft.Jet.OLEDB.4.0;User
ID=user;Data Source=folder_file;Mode=Share Deny None;Jet
OLEDB:Database Password=password;Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1")

this.Records.Open(sql,MDB,so

if(!this.Records.BOF) this.Records.MoveNext();

if(!this.Records.EOF) this.Records.MoveFirst();

this.Adapter.Fill(DS, this.Records, TableName)

Nov 16 '05 #7
thank you for this very complet answer

rgds, Wilfried
Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Mike MacSween | last post: by
4 posts views Thread by Eifel-benz | last post: by
3 posts views Thread by Russell Read [MSFT] | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.