0% found this document useful (0 votes)
28 views

Data Base

The document discusses the key objects used to handle databases in C#: OleDbConnection, OleDbCommand, and OleDbDataReader. It explains that OleDbConnection is used to create a connection object and requires a connection string specifying the database type, name, and login credentials. OleDbCommand is used to create command objects containing SQL statements to execute queries or commands. And OleDbDataReader is used to store and read data returned by OleDbCommand queries and provides methods to access field values.

Uploaded by

l410
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Data Base

The document discusses the key objects used to handle databases in C#: OleDbConnection, OleDbCommand, and OleDbDataReader. It explains that OleDbConnection is used to create a connection object and requires a connection string specifying the database type, name, and login credentials. OleDbCommand is used to create command objects containing SQL statements to execute queries or commands. And OleDbDataReader is used to store and read data returned by OleDbCommand queries and provides methods to access field values.

Uploaded by

l410
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Database Handling in C#

Namespace to be Used System.Data.OleDb; Three Objects to be used OleDbConnection OleDbCommand OleDbDataReader

OleDbConnection
How to Create Connection Object
OleDbConnection cnn ; cnn=new OleDbConnection(connString); What is This Connection String ?
Tells where and what kind of database is to be used by specifying

data base provider(type) Database name or Data Source User Id and Password

Connection String
Connection String to Connect with MS-Access "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\abc.mdb Connection String to Connect with MS-SQL Server provider=SQLOLEDB.1;database=master;data source =.;uid = sa Connection String to Connect with Oracle Server "provider=msdaora.1;data source =orcl;uid = shikha; passwd=a Connection String to Connect with MS-Access 2007 Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\emp.accdb;Persist Security Info=False

OleDbCommand
How to Create Command Object
OleDbCommand cmd cmd=new OleDbCommand (SQL Statment,connObject);

What is the SQL statement?


Like

Select * from emptable; Insert into emptable values (name, 2000,12); Update emptable set Name=Raj where empID=10001
ConnObject is what we have created in prev. Slide

OleDbDataReader
Why ??
To Store Data returned by Command object To be Declared only: OleDbDataReader dr; dr will be created and data will be stored when command object will execute : dr = cmd.ExecuteNonQuery(); dr= cmd.ExecuteReader();

Reading data
Data can be read from dr object by calling following methods: dr.Read(); //first row will be read n = dr.GetInt32(0); //first field will be read s=dr.GetString(1); //second field will be read as string d=dr.GetDateTime(2);
date //third field will be read as

s=dr.GetValue(3); //fourth field will be read as object

You might also like