473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 18948
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Mike MacSween | last post by:
My client has an MS Access database application on her local machine. I have full access to that in terms of changing the design. I've got a simple PHP/MySql application on shared hosting, so no...
4
by: Peter Larsson | last post by:
Hello everybody, I'm developing a system for a company that has production at two different locations. The production is stored in an Access database at each location, and I need to find a way...
1
by: James | last post by:
Hi, I am trying to access the MS Access database on my local machine in C# Windows Application in Visual Studio.NET. But it seems that it does not work. I use the Microsoft Application Blocks to...
4
by: Eifel-benz | last post by:
How to get connection to a MS Access database? How to read from a MS Access database? How to close the connection to a MS Access database?
3
by: Russell Read [MSFT] | last post by:
Hi all, I am using VB script in ASP to access a MS Access database. This works fine until I want to access the same db placed on a file share. The code I am using is... 'create connection...
14
by: Nick Gilbert | last post by:
Hi, I have an asp.net application which runs from a CD-ROM using Cassini. As such, it is single user only. The application connects to an Access database when it is loaded, and keeps the same...
0
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get:...
5
by: samadams_2006 | last post by:
I'm having a problem in accessing a Microsoft Access Database in a VB.NET Web Application. It's so straight forward, I thought I'd walk you through all the details here: 1) I have a .NET Web...
18
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft...
4
by: Rodent | last post by:
I have an IIS 6.0, 2003 Server running with PHP installed. I have an access database with a DSN ODBC connection configured. When this ODBC is configured to access the database locally - great,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.