58
Introducing ADO.NET By PRATIK Gohil Sr Lecturer SVICS Kadi Sr . Lecturer , SVICS, Kadi www.p2gohil.blogspot.com Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Understanding ADO

  • Upload
    pratik

  • View
    131

  • Download
    2

Embed Size (px)

DESCRIPTION

This presentation is uploaded to explain working of ADO.NET through code. I have demonstrated concept through Visual Basic Language.

Citation preview

Page 1: Understanding ADO

Introducing ADO.NET

By PRATIK Gohil

Sr Lecturer SVICS KadiSr. Lecturer, SVICS, Kadi

www.p2gohil.blogspot.com

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 2: Understanding ADO

Introduction to ADOIntroduction to ADO ADO .NET is a set of classes that allow .NET -based

l d d d f applications to read and update information in databases and other data stores. You can access these classes through the System.Data namespace provided classes through the System.Data namespace provided by the .NET Framework.

ADO .NET provides consistent access to a wide pvariety of data sources, including Microsoft SQL Server™ databases, OLE DB–compliant databases,

l ti l h Mi ft E h non-relational sources such as Microsoft Exchange Server, and XML documents.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 3: Understanding ADO

Earlier data access methods, such as Data Access Object (DAO), concentrate on tightly coupled, connected data environments. One of the main purposes of ADO NET is to enhance the purposes of ADO .NET is to enhance the disconnected data capabilities.

The ADO NET data providers contain tools to The ADO .NET data providers contain tools to allow you to read, update, add, and delete data in multi tier environments. Most of the objects in the jtwo libraries are similar and are identified by the prefix on their name.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 4: Understanding ADO

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 5: Understanding ADO

Benefits of ADO NetBenefits of ADO.Net Designed for disconnected data: ADO .NET is

designed for working with disconnected data in a multi tier environment. It uses XML as the format for transmitting disconnected data which makes it easier to communicate disconnected data, which makes it easier to communicate with client applications that are not based on Windows.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 6: Understanding ADO

Intrinsic to the .NET Framework: Because ADO .NET is intrinsic to the .NET Framework, you have all the advantages of using the .NET Framework, including ease of cross-language developmentcross language development.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 7: Understanding ADO

ADO Net Data ProvidersADO.Net Data Providers The .NET data providers allow access to specific types of

data sources. You can use the System.Data.SQLClientnamespace to access SQL Server 7.0 and later databases, and the System.Data.OLEDB namespace to access any data the System.Data.OLEDB namespace to access any data source exposed through OLE DB.

Each of these providers contains four main objects that you p ycan use to connect to a data source, read the data, and manipulate the data prior to updating the source.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 8: Understanding ADO

Using Connection ObjectUsing Connection Object To connect to a database, you set the connection type,

if th d t d t t th d t Wh specify the data source, and connect to the data source. When you are finished working with the data, you close the connection.

The SqlConnection object is optimized for SQL Server 7.0 and later databases by bypassing the OLE DB layer.

Th OLE DB NET D t P id The OLE DB .NET Data Provider uses a ConnectionString that is identical to that of ADO, except that the Provider keyword is now required.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 9: Understanding ADO

Using Command ObjectUsing Command Object You can use the ADO .NET Command object to execute

d d ti ll t t d t f d t commands and, optionally, to return data from a data source. You can use the SqlCommand with SQL Server databases and the OleDbCommand with all other types of data sources.

You can only execute a Command within a valid and open connection connection.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 10: Understanding ADO

The Command object provides three methods that you can use to execute commands: ExecuteReader: Use this method when the query will

return a stream of data such as a Select statement return a stream of data such as a Select statement returning a set of records. This method returns the records in a SqlDataReader or OleDbDataReader object.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 11: Understanding ADO

ExecuteScalar: Use this method when the query will return a singleton value; for example, a Select statement returning an aggregate value. It executes the query and returns the first column of the first row in the result set returns the first column of the first row in the result set, ignoring any other data that is returned. This method requires less code than using the ExecuteReader method and accessing a single value from the SqlDataReaderobject.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 12: Understanding ADO

ExecuteNonQuery: Use this method when the query will not return a result; for example, an Insert statement.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 13: Understanding ADO

SQLCommand ExecutionSQLCommand ExecutionDim conSQL As SqlClient.SqlConnectionconSQL = New SqlClient SqlConnection( )conSQL = New SqlClient.SqlConnection( )conSQL.ConnectionString = "Integrated Security=True;" & _"Data Source=LocalHost;Initial Catalog=Pubs;"Data Source=LocalHost;Initial Catalog=Pubs;

conSQL.Open( )Dim commSQL As SqlClient.SqlCommand

l li l d( )commSQL = New SqlClient.SqlCommand( )commSQL.Connection = conSQLcommSQL.CommandText = "Select Count(*) from

h "Authors"MessageBox.Show(commSQL.ExecuteScalar().ToString)

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 14: Understanding ADO

Using DataReader ObjectUsing DataReader Object You can use the DataReader object to create a read-only,

forward-only stream of data. This is an efficient method for accessing data that you only need to read through once. You can improve application performance by using this object can improve application performance by using this object because it holds only a single row of data at a time in memory instead of caching the entire set of records.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 15: Understanding ADO

You can instantiate the DataReader object by using the ExecuteReader method of the Command object. After you create the DataReader, you can call the Read method to obtain data in the rows You can access the columns by to obtain data in the rows. You can access the columns by name, ordinal number, or native type in conjunction with ordinal number.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 16: Understanding ADO

Dim datRead As SqlClient.SqlDataReader

d tR d SQL E t R d ( )datRead = commSQL.ExecuteReader( )

Do Until datRead.Read = False

MessageBox.Show(datRead(1).ToString_ & " " & datRead(0).ToString)

Loop

datRead.Close( )datRead.Close( )

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 17: Understanding ADO

Returning Multiple Result SetsReturning Multiple Result Sets Sometimes you will issue commands that return more than

one result set.

By default, the DataReader will only read the first result set You can use the NextResult method of the set. You can use the NextResult method of the DataReader to retrieve the next result set into the DataReader object. If there are no more result sets, this method returns False.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 18: Understanding ADO

CREATE PROCEDURE MultiResult AS

S l t * f thSelect * from authors

Select * from titles

Return 0

GO

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 19: Understanding ADO

commSQL.CommandText = "MultiResult"

Dim datRead As SqlClient.SqlDat aReaderdatRead = commSQL.ExecuteReader( )DoDo Until datRead.Read = False

MessageBox.Show(datRead.GetString(1))Loop

Loop While datRead.NextResult

datRead.Close( )

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 20: Understanding ADO

Using the DataAdapter ObjectUsing the DataAdapter Object You can use the DataAdapter object to exchange data

between a data source and a DataSet. You can use it to retrieve appropriate data and insert it into DataTableobjects within a DataSet and to update changes from the objects within a DataSet, and to update changes from the DataSet back into the data source.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 21: Understanding ADO

Using Existing Connection ObjectUsing Existing Connection Object Create a Command object within a Connection object,

and assign the SelectCommand property of the previously instantiated DataAdapter object to that command. This technique is useful if you need to create a Connection technique is useful if you need to create a Connection object specifically for the DataAdapter object to use.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 22: Understanding ADO

Dim comSQL As SqlClient.SqlCommandcomSQL = New SqlClient SqlCommand( )comSQL = New SqlClient.SqlCommand( )comSQL.Connection = conSQLcomSQL.CommandText = "Select * from authors"i iDim adaptSQL As SqlClient.SqlDataAdapter

adaptSQL = New SqlClient.SqlDataAdapter( )adaptSQL.SelectCommand = comSQL

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 23: Understanding ADO

Using Closed ConnectionUsing Closed Connection Instantiate the DataAdapter object, passing a query string

d C ti bj t Th D t Ad t ill h k and a Connection object. The DataAdapter will check whether the Connection is open, and, if it is not open, it will open it for you and close it when your method call is complete. This method is useful if you have already set the properties of a Connection object in your application and only need the connection to be opened to populate the data y p p ptables.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 24: Understanding ADO

Dim Adapter1 As New OleDb.OleDbDataAdapter ( _

"S l t * f l " C ti 1)"Select * from employee", Connection1)

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 25: Understanding ADO

Filling the DataTableFilling the DataTable After the DataAdapter object is created, you use the Fill

th d i D t S t d ti ll th i d method, passing a DataSet and, optionally, the required DataTable name as parameters.

You can then work with the data in your application, and, if y pp , ,required, you can use the Update method of the DataAdapter to synchronize those changes back to the data sourcesource.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 26: Understanding ADO

Adapter1 = New OleDb.OleDbDataAdapter("Select * From Employee" Connection1)From Employee , Connection1)

DS1 = New DataSet

Adapter1.Fill(DS1, "Employee")

‘Data Menipulation

Adapter1.Update(DS1, "Employee")Adapter1.Update(DS1, Employee )

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 27: Understanding ADO

The DataSet ObjectThe DataSet Object DataSets are the primary object that you will work with

when accessing disconnected sets of data. They are similar in concept to groups of ADO disconnected recordsets, but in ADO NET there are many enhancements including the ADO .NET, there are many enhancements, including the ability to relate tables together.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 28: Understanding ADO

P bl ith T Ti A li tiProblems with Two-Tier Applications In traditional two-tier applications, a data source connection

was often made at the start of the application and held open was often made at the start of the application and held open until the application ended. This can cause many problems, including: Poor performance: Database connections use valuable Poor performance: Database connections use valuable

system resources, such as memory and CPU utilization. The database server performance will be affected if a large number of connections are needlessly held opennumber of connections are needlessly held open.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 29: Understanding ADO

Limited scalability: Applications that consume a large number of database connections are not scalable because most data sources can only support a limited number of connectionsconnections.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 30: Understanding ADO

Disconnected Data in ADO NETDisconnected Data in ADO .NET ADO .NET is designed for use in the Internet world,

whereas COM may not be supported by all tiers, and may not be transmitted through firewalls. The disconnected architecture has been updated from the previous two-tier architecture has been updated from the previous two tier, RDO, and ADO architectures.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 31: Understanding ADO

ADO .NET provides you with a new object for the caching of data on the client computer. This object is known as a DataSet. This object is automatically disconnected from the data source but maintains the ability to later update the data source but maintains the ability to later update the source based on changes made at the client.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 32: Understanding ADO

The DataSet ObjectThe DataSet Object The DataSet object is a disconnected, memory resident

cache of data.

It is structured in a similar manner to a database in that it contains DataTable DataRelation and Constraint contains DataTable, DataRelation, and Constraint objects.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 33: Understanding ADO

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 34: Understanding ADO

DataSetsDataSets A typical use of a DataSet is through Services. A li t li ti ill k t f d t t S i A client application will make a request for data to a Service

that will populate a DataSet (using a DataAdapter) and return it to the client. The client can then view and modify th DataSet b i ti d th d th t the DataSet by using properties and methods that are consistent with database operations, and then pass it back to the Web Service. Th S i ill h d h d b i h h li ’ The Service will then update the database with the clients’ changes. The DataSet is transmitted between tiers as XML, which means that it can be also be used by non-ADO .NET li tclients.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 35: Understanding ADO

DataTables and DataRelationsDataTables and DataRelations The DataSet contains the Tables and Relations

ll ti U i bj t ithi th t ll ti collections. Using objects within these two collections, you can build up a group of related tables within your DataSet.

The DataTable object consists of the Columns collection jand the Rows collection. You can use the objects in these collections to manipulate the fields and query their properties The Relations collection contains definitions of properties. The Relations collection contains definitions of all the relationships between the DataTable objects in the DataSet. You can use these to enforce constraints on your d t t i t t bldata or to navigate across tables.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 36: Understanding ADO

Populating DataSetsPopulating DataSets You use a DataAdapter to access data stored in a database,

and store the data in DataTable objects within a DataSet in your application.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 37: Understanding ADO

P g ti ll C ti g D t S tProgrammatically Creating DataSetsDim tbl1 As New DataTable("Employee1")

tbl1 C l Add("E l N "tbl1.Columns.Add("EmployName", System.Type.GetType("System.String"))

Adapter1.Fill(DS1, "Employee1")

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 38: Understanding ADO

The basis of most RDBMSs is the ability to relate tables to h th each other.

ADO .NET provides this ability within DataSets through the DataRelation class.

Each DataRelation object contains an array of DataColumn objects that define the parent column or

l i k d th hild l l columns, or primary key, and the child column or columns, or foreign key, in the relationship. Referential integrity is maintained by the relationship, and you can specify how to deal with related changes.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 39: Understanding ADO

Adapter1 = New OleDb.OleDbDataAdapter("Select * From Employee", Connection1)p y

DS1 = New DataSetAdapter1.Fill(DS1, "Employee")

Adapter1 = New OleDb.OleDbDataAdapter("Select * From Salary", Connection1)

Adapter1.Fill(DS1, "Salary")Dim Rel As DataRelation

Rel = New DataRelation("EmpNumber", DS1 Tables(0) Columns(0) DS1 Tables(1) Columns(DS1.Tables(0).Columns(0),DS1.Tables(1).Columns(0))

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 40: Understanding ADO

Accessing Related DataAccessing Related Data The main use of a DataRelation is to allow access to related

records in a different table. You can do this by using the GetChildRows method of a DataRow object that returns an array of DataRow objectsan array of DataRow objects.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 41: Understanding ADO

Dim Rel As DataRelationRel = New DataRelation("EmpNumber",Rel New DataRelation( EmpNumber ,

DS1.Tables(0).Columns(0),

DS1.Tables(1).Columns(0))DS1.Relations.Add(Rel)

Dim MainRow As DataRowDim AccessRow As DataRowDim ChildRows() As DataRow

MainRow = DS1.Tables(0).Rows(0)ChildRows =

MainRow.GetChildRows("EmpNumber")

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 42: Understanding ADO

Dim i As ShortDim i As ShortFor i = 0 To UBound(ChildRows)AccessRow = ChildRows(i)

MsgBox(AccessRow(0).ToString +MsgBox(AccessRow(0).ToString + " " + AccessRow(1).ToString + " " +

AccessRow(2).ToString)Next I

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 43: Understanding ADO

Updating Data in the DataSetUpdating Data in the DataSet After you have created a DataSet of DataTables, you might

want to add, update, and delete data. Any changes you make to the data are stored in memory and later used to apply the changes to the data sourcechanges to the data source.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 44: Understanding ADO

Adding New RowAdding New Row'Adding New Row

Dim newRow As DataRow =Dim newRow As DataRow

DS1.Tables(0).NewRownewRow(0) = "S4"newRow(1) = “Avinash"newRow(2) = "Sales"newRow(3) = "Manager"newRow(4) = 10000

DS1.Tables(0).Rows.Add(newRow)

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 45: Understanding ADO

Generating Query AutomaticallyGenerating Query AutomaticallyDim OleDbCommandBuilder As New OleDb OleDbCommandBuilder(Adapter1)OleDb.OleDbCommandBuilder(Adapter1)

Adapter1.Update(DS1, "Employee")

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 46: Understanding ADO

DBConn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.;Data Source=emp1 mdb");Data Source emp1.mdb )

DBAdptr = New OleDb.OleDbDataAdapter("Select * From EmpDB", DBConn)DBDataSet = New DataSetDBAdptr.Fill(DBDataSet, "Employee")

Dim dr As DataRow = DBDataSet.Tables(0).NewRow

dr.Item(1) = "Sailesh"d (2) " "dr.Item(2) = "HR"dr.Item(3) = "Head"dr.Item(4) = 5000

DBDataSet.Tables(0).Rows.Add(dr)

Dim a As Ne OleDb OleDbCommandB ilder(DBAdptr)

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Dim a As New OleDb.OleDbCommandBuilder(DBAdptr)DBAdptr.Update(DBDataSet, "Employee")

Page 47: Understanding ADO

Editing Existing RowEditing Existing RowDim editRow As DataRow = DS1.Tables(0).Rows(0)

editRow.BeginEdit()

editRow.Item(0) = editRow.Item(0) + "1"

editRow.EndEdit()

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 48: Understanding ADO

Removing Existing RowRemoving Existing RowDim deleteRow As DataRow = DS1.Tables(0).Rows(1)

DS1 T bl (0) R R (d l t R )DS1.Tables(0).Rows.Remove(deleteRow)

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 49: Understanding ADO

Confirming the ChangesConfirming the Changes To update the DataSet, you use the appropriate methods to

dit th t bl d th ll A tCh edit the table, and then call AcceptChanges or RejectChanges for the individual rows or for the entire table.

You can discover whether any changes have been made to a row since AcceptChanges was last called by querying its RowState propertyRowState property.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 50: Understanding ADO

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 51: Understanding ADO

Updating Data at the SourceUpdating Data at the Source After you have updated the tables in your DataSet, you

ill li h h h d l i will want to replicate those changes to the underlying data source. To do this, you use the Update method of the DataAdapter object, which is the link between p j ,DataSet and data source.

The Update method, like the Fill method, takes two parameters: the DataSet in which the changes have been made and the name of the DataTable in which the changes are. It determines the changes to the data and changes are. It determines the changes to the data and executes the appropriate SQL command (Insert, Update or Delete) against the source data.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 52: Understanding ADO

Explicitly Specifying the UpdatesExplicitly Specifying the Updates You use the InsertCommand, UpdateCommand, and

DeleteCommand properties of the DataAdapter to identify the changes occurring in your DataSet.

You specify each of these as an existing command object for You specify each of these as an existing command object for an Insert, Update, or Delete SQL statement.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 53: Understanding ADO

Updating Data at the SourceUpdating Data at the Source After you have updated the tables in your DataSet, you

ill li h h h d l i will want to replicate those changes to the underlying data source. To do this, you use the Update method of the DataAdapter object, which is the link between p j ,DataSet and data source.

The Update method, like the Fill method, takes two parameters: the DataSet in which the changes have been made and the name of the DataTable in which the changes are. It determines the changes to the data and changes are. It determines the changes to the data and executes the appropriate SQL command (Insert, Update or Delete) against the source data.

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 54: Understanding ADO

You use the InsertCommand, UpdateCommand, and DeleteCommand properties of the DataAdapter to identify the changes occurring in your DataSet. You

if h f th i ti d bj t f specify each of these as an existing command object for an Insert, Update, or Delete SQL statement.

For any variable columns in the statements you use For any variable columns in the statements, you use SqlParameter objects to identify the column, data type, size, and data to be inserted.yp , ,

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 55: Understanding ADO

Adapter1 = New OleDb.OleDbDataAdapter("Select * From Employee", Connection1)

Dim DS As DataSetDim DS As DataSetDS = New DataSetAdapter1.Fill(DS, "Employee")

Dim NewRow As DataRow = DS.Tables(0).NewRowNewRow("empNo") = "S5"NewRow("empName") = "Pratik Gohil"NewRow( empName ) Pratik GohilNewRow("empDepartment") = "New Department"NewRow("empDesignation") = "New Designation"NewRow("empBasic") = 12000( p )

DS.Tables(0).Rows.Add(NewRow)

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 56: Understanding ADO

Command1 = New OleDb.OleDbCommandCommand1.Connection = Connection1Command1.CommandText = "Insert into

Employee(empNo, empName, empDepartment, empDesignation, empBasic) values(@empNo, @empName,empDesignation, empBasic) values(@empNo, @empName, @empDepartment, @empDesignation, @empBasic)"

Command1.Parameters.Add("@empNo", l b l b h 10 " ")OleDb.OleDbType.Char, 10, "empNo")

Command1.Parameters.Add("@empName", OleDb.OleDbType.Char, 50, "empName")

Command1 Parameters Add("@empDepartment"Command1.Parameters.Add( @empDepartment , OleDb.OleDbType.Char, 10, "empDepartment")

Command1.Parameters.Add("@empDesignation", OleDb.OleDbType.Char, 10, "empDesignation")

Command1.Parameters.Add("@empBasic", OleDb.OleDbType.Integer, 10, "empBasic")

Adapter1 InsertCommand Command1

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Adapter1.InsertCommand = Command1Adapter1.Update(DS, "Employee")

Page 57: Understanding ADO

Generating Query AutomaticallyGenerating Query AutomaticallyDim OleDbCommandBuilder As New OleDb OleDbCommandBuilder(Adapter1)OleDb.OleDbCommandBuilder(Adapter1)

Adapter1.Update(DS1, "Employee")

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Page 58: Understanding ADO

DBConn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=emp1.mdb")p

DBAdptr = New OleDb.OleDbDataAdapter("Select * From EmpDB", DBConn)DBDataSet Ne DataSetDBDataSet = New DataSetDBAdptr.Fill(DBDataSet, "Employee")

Dim dr As DataRow = DBDataSet Tables(0) NewRowDim dr As DataRow = DBDataSet.Tables(0).NewRow

dr.Item(1) = "Sailesh"dr Item(2) = "HR"dr.Item(2) = HRdr.Item(3) = "Head"dr.Item(4) = 5000

DBDataSet.Tables(0).Rows.Add(dr)

Dim a As New OleDb OleDbCommandBuilder(DBAdptr)

Understanding ADO.NET By PRATIK Gohil (p2gohil.blogspot.com)

Dim a As New OleDb.OleDbCommandBuilder(DBAdptr)DBAdptr.Update(DBDataSet, "Employee")