4123305 using ado net
Download
Skip this Video
Download Presentation
การเขียนโปรแกรมภาษาคอมพิวเตอร์ขั้นสูง 4123305 Using ADO.NET

Loading in 2 Seconds...

play fullscreen
1 / 19

4123305 Using ADO - PowerPoint PPT Presentation


  • 71 Views
  • Uploaded on

โดย อ. นัฐพงศ์ ส่งเนียม สาขาวิชา เทคโนโลยีสารสนเทศ และ สาขาวิชา วิทยาการคอมพิวเตอร์ คณะวิทยาศาสตร์และเทคโนโลยี มหาวิทยาลัยราชภัฏพระนคร http://www.siam2dev.com [email protected] [email protected] [email protected]

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' 4123305 Using ADO' - butch


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
4123305 using ado net

โดย อ. นัฐพงศ์ ส่งเนียม

สาขาวิชา เทคโนโลยีสารสนเทศ และ

สาขาวิชา วิทยาการคอมพิวเตอร์

คณะวิทยาศาสตร์และเทคโนโลยี มหาวิทยาลัยราชภัฏพระนคร

http://www.siam2dev.com

[email protected]

[email protected]

[email protected]

การเขียนโปรแกรมภาษาคอมพิวเตอร์ขั้นสูง4123305Using ADO.NET

disconnected model1

VB4 user id=sa;

password=123

DataAdapter

Fill

Update

UpdateCommand

Disconnected Model

DataSet

Connection

SelectCommand

CommandBuilder

ado net object model
ADO.NET Object Model

System.Data

DataSet

DataTable

DataReader

CommandBuilder

DataRow

Update

DataColumn

DataAdapter

Command

Constraint

Fill

Connection

DataRelation

Database

XML File

importing namespace
Importing Namespace

Oledb

\'Connect to database via OLEDB

Imports System.Data.Oledb

SqlClient

\'Connect to SQL Server database only

Imports System.Data.SqlClient

oledbconnection
OledbConnection

Initial Object

Connect to Microsoft Access

Public CN as New OledbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=FileName.MDB")

Connect to Microsoft SQL Server

Public CN as New OledbConnection("Provider=SQLOLEDB;" & _

"Data Source=ServerName;Initial Catalog=DatabaseName;" & _

User ID=UserName;Password=Password;")

Connect to Database Using UDL

Public CN as New OledbConnection("File Name=FileName.UDL")

sqlconnection
SqlConnection

Initial Object

Connect to Microsoft SQL Server

Public CN as New SQLConnection("Data Source=ServerName;" & _

Initial Catalog=DatabaseName;" & _

User ID=UserName;Password=Password;")

connection methods
Connection Methods
  • Open

Open a database connection with the property settings specified by the ConnectionString.

  • Close

Close the connection to the data source. )

  • Dispose

Release the resources used by the Component.

dataset and dataadapter objects
DataSet and DataAdapter Objects

DataSet

DataAdapter

Data Source

DataTable

SelectCommand

Fill

CommandBuilder

Update

Connection

UpdateCommand

DataAdapter

DataTable

SelectCommand

Fill

CommandBuilder

Update

UpdateCommand

dataset
DataSet
  • Datasets can include multiple DataTables
  • Relationships between tables are represented using DataRelations
  • Constraints enforce primary and foreign keys
  • Use the DataRow and DataColumn to access values in Tables

DataColumn

DataRow

DataTable

DataRelation

dataadapter
DataAdapter
  • Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.

Fill data from data source to DataSet

SQL = "Select Sataement…"

Dim DS as New DataSet("Name")

Dim DA as New OledbDataAdapter(SQL,CN)

DA.Fill(DS,"TableName")

retriving data from dataset
Retriving data from DataSet

Table Name

Column Name

TextBox1.Text = DS.Tables("Customer").Rows(2)("Name")

Row number

DataSet

Customer

Product

commandbuilder
CommandBuilder

Automatically generating single-table commands used to reconcile changes made to a DataSet with the associated database.

Fill data from data source to DataSet (Using CommandBuilder)

SQL = "Select Sataement…"

Dim DS as New DataSet

Dim DA as New OledbDataAdapter(SQL,CN)

Dim CB as New OledbCommandBuilder(DA)

DA.Fill(DS,"TableName")

Update DataSet to data source.

DA.Update(DS,"TableName")

datarow
DataRow

DataColumn

  • Delete an existing row

DataRow

DataTable

DataRelation

DataSet1.Tables("TableName").Rows({number})

DataSet1.Tables("TableName").Rows({number}).Delete

insert and update data
Insert and update data
  • Insert Data
  • Update Data

Dim DR1 As DataRow = DataSet1.Tables("Person").NewRow()

DR1("ID") = "001"

DR1("Name") = "Peter"

DataSet1.Tables("Person").Rows.Add(DR1)

DataSet1.Tables("Person").Rows(2)("ID") = "001"

DataSet1.Tables("Person").Rows(2)("Name") = "Peter"

datagrid control
DataGrid Control
  • Show data from DataTable on user interfaces.
  • Display tabular data and allowing for updates to the data source.
  • Can be used to display either a single table or the hierarchical relationships between a set of tables.

Seting DataSource

DataGrid1.DataSource=DS.Tables("Customer")

method showdata
Method ShowData
  • Used for retrieving data from DataSet and showing on TextBox.

Private i As Integer = 0

Private Sub ShowData( )

Try

TextBox1.Text = DS.Tables("Student").Rows(i)("StuID")

TextBox2.Text = DS.Tables("Student").Rows(i)("StuName")

TextBox3.Text = DS.Tables("Student").Rows(i)("StuTel")

Catch ex As Exception

\' Message something

End Try

End Sub

method movedata
Method MoveData
  • Used for moving the cursor.

Private Sub MoveData(Number As Integer)

Dim Count As Integer = DS.Tables("Student").Rows.Count()

If ( i + Number >= 0 ) AndAlso ( i + Number < Count ) Then

i += Number

ShowData()

Else

\' Message Something

End If

End Sub

method movefirst and movelast
Method MoveFirst and MoveLast
  • Used for moving the cursor to the first row or the last row of the table.

Private Sub MoveFirst( )

i = 0

ShowData()

End Sub

Private Sub MoveLast( )

Dim Count As Integer = DS.Tables("Student").Rows.Count()

i = Count - 1

ShowData()

End Sub

ad