Chapter 5 Notes
Chapter 5 Notes
Chapter-5
Data Access with ADO.NET
Definition:
ADO.NET is a module of .net framework which is used to established connection
between front end application and data sources.
ADO.NET provides a bridge between the front end controls and the back end database.
Data sources can be such as SQL Server and XML. ADO.NET consists of classes that
can be used toconnect, retrieve, insert and delete data.
Architecture of ADO.NET
The following figure shows the ADO.NET objects:
ADO.NET has two main components that are used for accessing and manipulating data.
They are
Data Provider
Data Set
Data Providers:
These are the components that are designed and data manipulation and fast access to data.
It provides various objects such as
Connection,Command, Data Reader and Data Adapter that are used to perform
database operations.
Data Reader It is used to read data from data source. The Data Reader is a
base class for all Data Reader objects.
The ADO.NET Framework provides the following data providers that we can use in our
application.
Data Set:
It is a subset of the database; it does not have continuous connection to the database.
DataTableCollection:
The Data Table class represents the tables in the database. It has the following
important properties;most of these properties are read only properties except the
Primary Key property:
Properties
Data Reader does not perform in disconnected mode. It requires Data Reader object
to be connectedand It receives only one table and view at a time. Whereas Dataset
can receives multiple tables at a time.
After we are establishing Connection then we can provide which command we have
to pass as anargument.
Syntax:
Here first we need create Dataset and create an object for this dataset.
Go to “Solution Explorer” widow => right click on the project name => click on
“Add” option =>Select “add new item” => select “service Based database” => click
GFGC, Tumkur Dept. of BCA Page 6
C# and Dot net framework
on “Add”.
Step 2: If we wants to rename database => right click on the project => using rename
option we canrename the database.
Step 3: now we need to create a table in the database. For this => double click on the
data base => willopen “server explorer” window => select “table” option => right click
on this => select “add new table” => new table will be added to the database.
Step 4: If we want to change the table name then we can change as “dbo.Student”
and will add somecolumns into that table like “ID, SName and Smarks etc.”
Step 5: After entering these details in to table then we need to Update the table by using
“update”
Step 8: We need to create / Establish Connection between Front end Form and Back end
Database forthat write the coding part.
MsgBox("connected successfully")
cn.Close()
End Sub
Step 12: for Inserting data in to the Table through VB.NET Coding
cn.Open()
cmd = cn.CreateCommand()
cmd.CommandText = "insert into Student values(" & TextBox1.Text & " , ' " &
TextBox2.Text &" ' , " & TextBox3.Text & ")"
cmd.ExecuteNonQuery()
MsgBox("record inserted successfully")
cn.Close()
End Sub
Step 13: Run the Project then it display “Connected Successfully” and insert some rows in
table.
Step 14: Run the query as select * from Student;
Step 14: Now we Update tuple or rows in table.
Query:
Update table name set column name1= value, column name2=value where
colname=value;
Step 15: For Updating Existing data in the Table through VB.NET Coding
cmd = cn.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "update Student set sname=' " & TextBox2.Text & " ' ,
smarks=" &TextBox3.Text & " where id=" & TextBox1.Text & ""
cmd.ExecuteNonQuery()
MsgBox("record updated successfully")
cn.Close()
End Sub
Step 16: Run the Project then it display “Connected Successfully” and update rows.
Query:
What is OLEDB?
Object Linking and Embedding Database (OLE DB) is a connectivity method similar to
Open Database Connectivity (ODBC) it represents a unique connection to a data source.
What is ODBC?
Open Database Connectivity (ODBC) is a standard application programming
interface (API) for accessing database management systems (DBMS).
*********