ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
?????? 3 ADO.NET3 ADO.NET ????
?????????????? AccessAccess
2003/20072003/2007
Suan Dusit Rajabhat University, Phitsanulok CampusSuan Dusit Rajabhat University, Phitsanulok Campus
Mr.Warawut KhangkhanMr.Warawut Khangkhan
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 2
??????????
¡ñ
???????????????????????????????
??? VS2008
¡ñ
???????????????????????????????
??./? ADO.NET
¡ñ
?????0???/?????????? Access 2003/2007
¡ñ
??????????? (Binding Data)
¡ñ
?????????????5??6 DataReader
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 3
??????????
¡ñ
????????????? Execute ????????5??6
Command
¡ñ
???????????????????????????? Access
2003/2007
¡ñ
?????????????5??6 Query ??????????
Access 2003/2007
¡ñ
??????????????? Access ???????:?
Transaction
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 4
??????????????????????????????????????????
?????????????????????????? VS2008VS2008
.NET 2.0
Windows Form Application
ADO.NET 2.0
¡ñ
SQL
.NET 3.0/3.5
LINQ
¡ñ
LINQ to Object
¡ñ
LINQ to SQL
¡ñ
LINQ to XML
WPF Application
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 5
????????????????????????????????????????
???? ?????????"#????? ?????????"#? ADO.NETADO.NET
¡ñ
????????./??????5??6 ADO.NET ?????
?????? (Design Time)
¡ñ
??????????????./??????5??6 ADO.NET ???
???????????????? (Run Time)
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 6
??"#??????%??'??"#??????%??' ADO.NETADO.NET
??"#???"#?
?????%??'?????%??'
?#????#???
?(?????(????
?#?????#????
??"#???"#?
?????%??'?????%??'
????????????
ADO.NETADO.NET
??"#???"#?
?????%??'????????%??'???
OLEDB DataOLEDB Data
ProviderProvider
Namespace System.Data.OleDb
??"#???"#?
?????%??'????????%??'???
SQL ServerSQL Server
DataData
ProviderProvider
Namespace System.Data.SqlClient
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 10
????????????%??'???????????????%??'???
??#???????#?????
¡ñ
?????%??' Connection
?:??????????????0???/?????????????
??? OleDbConnection ??0???/??????????
??? Access ?/?? SqlConnection ?:?????
??0???/????????????? SQL Server
¡ñ
?????%??' DataAdapter
?:???????5??.??:??? SQL ??0???????????
???????????? ?????6????0? ?????5??6
DataSet
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 11
????????????%??'???????????????%??'???
??#???????#?????
¡ñ
?????%??' DataSet
?:???????5??????6???????:???????????
????????????? ?????5??6 DataAdapter
?????????5??6???????????????????:???
?????.?
¡ñ
?????%??' Command
?:????????.??:??? SQL ?????6????0?
?????5??6 DataReader
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 12
????????????%??'???????????????%??'???
??#???????#?????
¡ñ
?????%??' DataReader
?:???????5??????6???????:???????????
??????? ??/????????????5??6 DataSet ??/
????????? ?????5??6 Command
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 13
?????0???/???????????????0???/?????????? AccessAccess
2003/20072003/2007
¡ñ
????????/????????/?? Access 2003/2007
Access 2003 ?????.? .mdb
Access 2007 ?????.? .accdb
¡ñ
?????0???/??????????
Access 2003
Provider=Microsoft.JET.OLEDB.4.0;data source=c:abc.mdb
Access 2007
Provider=Microsoft.ACE.OLEDB.12.0;data
source=c:abc.accdb;Persist Security Info=False
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 14
?????????????????????? (Binding Data)(Binding Data)
¡ñ
??????????? (Binding Data) ?0????????
?:?????B??0B?????????????????????????
???????
?????????????????????? (Binding Data)(Binding Data)
????C?????? ADO.NET ???/ 2 ??? ?0?
¡ñ
Simple Binding Data ???????????????
?????? ?0? ??????????????????
??????? DataGridView, TextBox, Label
?????? ?????????????????????????
????????? (??/??????0?????????????0??)
¡ñ
Complex Binding Data ??0???????????/?
????:? Lookup Table ?5?? ???????????
????????????????0??????????????6
????/??????? 2 ?????????????
?????????????%??'?????????????%??'
DataReaderDataReader
¡ñ
?:???????5?????????????????????
???? ???????/????B? 1 ??5????6? (record)
¡ñ
????????0???????? (Forward-Only) ????
??/??????
¡ñ
?????????????.??:??? SQL ????????5??6
Command
¡ñ
???????????????????????5? ??/? ???
??????????0?????/???/??EB??? ??0???????
??0??????????:????
¡ñ
????????????????????5??6 DataSet
?????????????????????????? ExecuteExecute ??????
?????5??6?????5??6 CommandCommand
¡ñ
????? ExecuteReader( )
?:????????.??:??? SQL ?????????????0?
?/?????? ??????????????5??6
DataReader
¡ñ
????? ExecuteScalar( )
?:???????/????????????
ExecuteReader( ) ??/???????/???5?0?
??????B?/??/???????????/???????/??B?
¡ñ
????? ExecuteQuery( )
?:????????.??:??? SQL ????????? ????
??0???????
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 18
??????#??????#???????%??'??????#??????#???????%??'
DataReaderDataReader ???????%??'???????%??'
DataSetDataSet
?????%??' DataReader
¡ñ
?:??????/?????????????????????
???????/????B??? 1 ??5????6?????? ?
????????0??????????? (Forward-Only)
??????/??????
¡ñ
???????????????????.??:??? SQL ???
?????5??6 Command ?/???????5??6 DataSet
?????????????.??:??? SQL ????????5??6
DataAdapter
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 19
??????#??????#???????%??'??????#??????#???????%??'
DataReaderDataReader ???????%??'???????%??'
DataSetDataSet
?????%??' DataReader (?#?)
¡ñ
????????????C?????? Connected ?????E?
??????0???/??????/????????????? ?/???
????0???????????5??6 DataReader ??? ???
????.??????G?-?G?????????5??6 DataReader
????B???? ??????/???/????????G??????5??6
DataReader ??? 1 ??B?????????????
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 20
??????#??????#???????%??'??????#??????#???????%??'
DataReaderDataReader ???????%??'???????%??'
DataSetDataSet
?????%??' DataSet
¡ñ
?/???????B????????????.??:??? SQL
??????????5???????/???????:? ????B???
?:?????????????? ?5?????/??????????
¡ñ
????????????????????5???/???????5??6
DataSet ???????/??????5??6 DataReader
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 21
??????#??????#???????%??'??????#??????#???????%??'
DataReaderDataReader ???????%??'???????%??'
DataSetDataSet
?????%??' DataSet (?#?)
¡ñ
????????????C?????? Disconnected ?E?
?????E? ??0??.????????????5???????
??5??6 DataSet ??? ?5?????????????0???/?
?????/?????????????????
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 22
????????????????????????????????????????????????
???????? Access 2003/2007Access 2003/2007
¡ñ
?????????????./??????5??6 ADO.NET ???
??????????????????? ??/?5?????????
???????E????/????????????/??/???? ??/
???????????????????????????????
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 23
?????????????5??6?????????????5??6 QueryQuery ??????
?????????????? Access 2003/2007Access 2003/2007
????????????????5??6 Query ?? 2 ?????
¡ñ
?????????????%??' Query ?????#????
?#??#?????? ?????E? ?.??:??? SQL ???5?
??/??????????6????????? ??????????/?
??????:????????.??:??? SQL ????/?????
???????
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 24
?????????????5??6?????????????5??6 QueryQuery ??????
?????????????? Access 2003/2007Access 2003/2007
????????????????5??6 Query ?? 2 ?????
(?/?)
¡ñ
?????????????%??' Query ????????#?
?#?????? ?????E? ??0?????????????:????
????.? SQL ???5???/???????5??6 Query
???????B ???????????/???/??.??:??? SQL
????/???????????????? ??????????/??
???????????????
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 25
?????????????????????????????? AccessAccess ??????
????:?????:? TransactionTransaction
¡ñ
????:? Transaction ?????????????? ??0???
??????/???0???????????????????? ??/?/?
??????????????0????????? ?????:???
????:??????????/??????????????.?
????????/?? Transaction ?????? ?E??????/
2 ???????/??B? ?0?
¨C ?????' 100% ??????????B?/? Commit
Transaction
¨C ?????? 0% ??????????B?/? Rollback
Transaction
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 26
???????:??????????????:??????? TransactionTransaction
¡ñ
?0? ??????????????????/?? Cache ?/??
??0????? Commit Transaction ?E?????/?B?
???????:????? ?E????????????????:???
???????/?????????? ??/?????????????:?
Rollback Transaction ?5????/???????????
???/????????????/??/???? ????????????
???????????/?? Cache ?????
¡ñ
???????:? Transaction ???B????????
Access ??? SQL Server
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 27
???????????????????????? TransactionTransaction
¡ñ
????? BeginTrans( ) ????????5??6
SqlConnection ??0???????:? Transaction
¡ñ
????? Commit( ) ????????5??6
SqlTransaction ??0? Commit Transaction
¡ñ
????? Rollback( ) ??0??:? Rollback
Transaction
K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 28
Contact usContact us
Mr.Warawut KhangkhanMr.Warawut Khangkhan
Social Media:
http://www.facebook.com/awarawut
http://twitter.com/awarawut
Web Site:
http://awarawut.blogspot.com
E-Mail:
awarawut@hotmail.com
warawut_kha@dusit.ac.th
Mobile:
083-0698-410

More Related Content

03 ado-dot-net-access

  • 1. ?????? 3 ADO.NET3 ADO.NET ???? ?????????????? AccessAccess 2003/20072003/2007 Suan Dusit Rajabhat University, Phitsanulok CampusSuan Dusit Rajabhat University, Phitsanulok Campus Mr.Warawut KhangkhanMr.Warawut Khangkhan
  • 2. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 2 ?????????? ¡ñ ??????????????????????????????? ??? VS2008 ¡ñ ??????????????????????????????? ??./? ADO.NET ¡ñ ?????0???/?????????? Access 2003/2007 ¡ñ ??????????? (Binding Data) ¡ñ ?????????????5??6 DataReader
  • 3. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 3 ?????????? ¡ñ ????????????? Execute ????????5??6 Command ¡ñ ???????????????????????????? Access 2003/2007 ¡ñ ?????????????5??6 Query ?????????? Access 2003/2007 ¡ñ ??????????????? Access ???????:? Transaction
  • 4. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 4 ?????????????????????????????????????????? ?????????????????????????? VS2008VS2008 .NET 2.0 Windows Form Application ADO.NET 2.0 ¡ñ SQL .NET 3.0/3.5 LINQ ¡ñ LINQ to Object ¡ñ LINQ to SQL ¡ñ LINQ to XML WPF Application
  • 5. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 5 ???????????????????????????????????????? ???? ?????????"#????? ?????????"#? ADO.NETADO.NET ¡ñ ????????./??????5??6 ADO.NET ????? ?????? (Design Time) ¡ñ ??????????????./??????5??6 ADO.NET ??? ???????????????? (Run Time)
  • 6. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 6 ??"#??????%??'??"#??????%??' ADO.NETADO.NET
  • 10. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 10 ????????????%??'???????????????%??'??? ??#???????#????? ¡ñ ?????%??' Connection ?:??????????????0???/????????????? ??? OleDbConnection ??0???/?????????? ??? Access ?/?? SqlConnection ?:????? ??0???/????????????? SQL Server ¡ñ ?????%??' DataAdapter ?:???????5??.??:??? SQL ??0??????????? ???????????? ?????6????0? ?????5??6 DataSet
  • 11. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 11 ????????????%??'???????????????%??'??? ??#???????#????? ¡ñ ?????%??' DataSet ?:???????5??????6???????:??????????? ????????????? ?????5??6 DataAdapter ?????????5??6???????????????????:??? ?????.? ¡ñ ?????%??' Command ?:????????.??:??? SQL ?????6????0? ?????5??6 DataReader
  • 12. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 12 ????????????%??'???????????????%??'??? ??#???????#????? ¡ñ ?????%??' DataReader ?:???????5??????6???????:??????????? ??????? ??/????????????5??6 DataSet ??/ ????????? ?????5??6 Command
  • 13. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 13 ?????0???/???????????????0???/?????????? AccessAccess 2003/20072003/2007 ¡ñ ????????/????????/?? Access 2003/2007 Access 2003 ?????.? .mdb Access 2007 ?????.? .accdb ¡ñ ?????0???/?????????? Access 2003 Provider=Microsoft.JET.OLEDB.4.0;data source=c:abc.mdb Access 2007 Provider=Microsoft.ACE.OLEDB.12.0;data source=c:abc.accdb;Persist Security Info=False
  • 14. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 14 ?????????????????????? (Binding Data)(Binding Data) ¡ñ ??????????? (Binding Data) ?0???????? ?:?????B??0B????????????????????????? ???????
  • 15. ?????????????????????? (Binding Data)(Binding Data) ????C?????? ADO.NET ???/ 2 ??? ?0? ¡ñ Simple Binding Data ??????????????? ?????? ?0? ?????????????????? ??????? DataGridView, TextBox, Label ?????? ????????????????????????? ????????? (??/??????0?????????????0??) ¡ñ Complex Binding Data ??0???????????/? ????:? Lookup Table ?5?? ??????????? ????????????????0??????????????6 ????/??????? 2 ?????????????
  • 16. ?????????????%??'?????????????%??' DataReaderDataReader ¡ñ ?:???????5????????????????????? ???? ???????/????B? 1 ??5????6? (record) ¡ñ ????????0???????? (Forward-Only) ???? ??/?????? ¡ñ ?????????????.??:??? SQL ????????5??6 Command ¡ñ ???????????????????????5? ??/? ??? ??????????0?????/???/??EB??? ??0??????? ??0??????????:???? ¡ñ ????????????????????5??6 DataSet
  • 17. ?????????????????????????? ExecuteExecute ?????? ?????5??6?????5??6 CommandCommand ¡ñ ????? ExecuteReader( ) ?:????????.??:??? SQL ?????????????0? ?/?????? ??????????????5??6 DataReader ¡ñ ????? ExecuteScalar( ) ?:???????/???????????? ExecuteReader( ) ??/???????/???5?0? ??????B?/??/???????????/???????/??B? ¡ñ ????? ExecuteQuery( ) ?:????????.??:??? SQL ????????? ???? ??0???????
  • 18. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 18 ??????#??????#???????%??'??????#??????#???????%??' DataReaderDataReader ???????%??'???????%??' DataSetDataSet ?????%??' DataReader ¡ñ ?:??????/????????????????????? ???????/????B??? 1 ??5????6?????? ? ????????0??????????? (Forward-Only) ??????/?????? ¡ñ ???????????????????.??:??? SQL ??? ?????5??6 Command ?/???????5??6 DataSet ?????????????.??:??? SQL ????????5??6 DataAdapter
  • 19. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 19 ??????#??????#???????%??'??????#??????#???????%??' DataReaderDataReader ???????%??'???????%??' DataSetDataSet ?????%??' DataReader (?#?) ¡ñ ????????????C?????? Connected ?????E? ??????0???/??????/????????????? ?/??? ????0???????????5??6 DataReader ??? ??? ????.??????G?-?G?????????5??6 DataReader ????B???? ??????/???/????????G??????5??6 DataReader ??? 1 ??B?????????????
  • 20. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 20 ??????#??????#???????%??'??????#??????#???????%??' DataReaderDataReader ???????%??'???????%??' DataSetDataSet ?????%??' DataSet ¡ñ ?/???????B????????????.??:??? SQL ??????????5???????/???????:? ????B??? ?:?????????????? ?5?????/?????????? ¡ñ ????????????????????5???/???????5??6 DataSet ???????/??????5??6 DataReader
  • 21. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 21 ??????#??????#???????%??'??????#??????#???????%??' DataReaderDataReader ???????%??'???????%??' DataSetDataSet ?????%??' DataSet (?#?) ¡ñ ????????????C?????? Disconnected ?E? ?????E? ??0??.????????????5??????? ??5??6 DataSet ??? ?5?????????????0???/? ?????/?????????????????
  • 22. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 22 ???????????????????????????????????????????????? ???????? Access 2003/2007Access 2003/2007 ¡ñ ?????????????./??????5??6 ADO.NET ??? ??????????????????? ??/?5????????? ???????E????/????????????/??/???? ??/ ???????????????????????????????
  • 23. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 23 ?????????????5??6?????????????5??6 QueryQuery ?????? ?????????????? Access 2003/2007Access 2003/2007 ????????????????5??6 Query ?? 2 ????? ¡ñ ?????????????%??' Query ?????#???? ?#??#?????? ?????E? ?.??:??? SQL ???5? ??/??????????6????????? ??????????/? ??????:????????.??:??? SQL ????/????? ???????
  • 24. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 24 ?????????????5??6?????????????5??6 QueryQuery ?????? ?????????????? Access 2003/2007Access 2003/2007 ????????????????5??6 Query ?? 2 ????? (?/?) ¡ñ ?????????????%??' Query ????????#? ?#?????? ?????E? ??0?????????????:???? ????.? SQL ???5???/???????5??6 Query ???????B ???????????/???/??.??:??? SQL ????/???????????????? ??????????/?? ???????????????
  • 25. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 25 ?????????????????????????????? AccessAccess ?????? ????:?????:? TransactionTransaction ¡ñ ????:? Transaction ?????????????? ??0??? ??????/???0???????????????????? ??/?/? ??????????????0????????? ?????:??? ????:??????????/??????????????.? ????????/?? Transaction ?????? ?E??????/ 2 ???????/??B? ?0? ¨C ?????' 100% ??????????B?/? Commit Transaction ¨C ?????? 0% ??????????B?/? Rollback Transaction
  • 26. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 26 ???????:??????????????:??????? TransactionTransaction ¡ñ ?0? ??????????????????/?? Cache ?/?? ??0????? Commit Transaction ?E?????/?B? ???????:????? ?E????????????????:??? ???????/?????????? ??/?????????????:? Rollback Transaction ?5????/??????????? ???/????????????/??/???? ???????????? ???????????/?? Cache ????? ¡ñ ???????:? Transaction ???B???????? Access ??? SQL Server
  • 27. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 27 ???????????????????????? TransactionTransaction ¡ñ ????? BeginTrans( ) ????????5??6 SqlConnection ??0???????:? Transaction ¡ñ ????? Commit( ) ????????5??6 SqlTransaction ??0? Commit Transaction ¡ñ ????? Rollback( ) ??0??:? Rollback Transaction
  • 28. K.Warawut ??? 3 ADO.NET ????????? Access 2003/2007 28 Contact usContact us Mr.Warawut KhangkhanMr.Warawut Khangkhan Social Media: http://www.facebook.com/awarawut http://twitter.com/awarawut Web Site: http://awarawut.blogspot.com E-Mail: awarawut@hotmail.com warawut_kha@dusit.ac.th Mobile: 083-0698-410