Data Base
Data Base
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);
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