‫اﻟﺒﺪء ﻣﻊ‬

‫‪ADO.NET‬‬

‫أن ﻣﺎ دﻋﺎﻧﻲ ﻟﺒﺪء ھﺬا اﻟﺸﺮح ھﻮ اﻟﺘﻄﻮر اﻟﻤﺴﺘﻤﺮ ﻟﻠﺒﺮﻣﺠﺔ وﺻﻌﻮﺑﺔ أﯾﺠﺎد ﺷﺮح واﻓﻲ ﻟﻌﻤﻠﯿﺔ‬
‫اﻻﺗﺼﺎل وﻣﺤﺎﻛﺎة ﻗﺎﻋﺪة‬
‫ﺑﯿﺎﻧﺎت ﻣﻦ ﺣﻔﻆ واﺳﺘﺮﺟﺎع وﺗﺤﺪﯾﺚ وﺑﺤﺚ ‪ ..‬أﻟﺦ ‪ .‬ﻓﻜﻞ ﻣﺎ ﻧﺠﺪه ھﻮ اﻷﻣﺜﻠﮫ واﻟﻤﺸﺎرﯾﻊ اﻟﺸﺨﺼﯿﺔ‬
‫اﻟﺠﺎھﺰة وھﻲ ﻣﻔﯿﺪة‬
‫وﻟﻜﻦ ﻻ ﯾﻜﻮن أﺛﺮھﺎ ﻛﺎﻟﺪرس اﻟﻤﺸﺮوح ﻓﺄﻏﻠﺒﯿﺘﻨﺎ ﯾﻔﺘﻘﺪ ﻷﻗﻞ ﻣﻌﻠﻮﻣﮫ وأﺳﺮﻋﮭﺎ وأن ﺗﻜﻮن ﺳﮭﻠﺔ اﻟﻔﮭﻢ‬
‫ﻟﻜﻲ ﯾﺴﺘﻮﻋﺒـــــﮭﺎ‬
‫اﻟﻤﺒﺘﺪء ﻗﺒﻞ اﻟﻤﺤﺘﺮف ﻛﺤﺎﻟﻲ ﻋﻨﺪﻣﺎ ﺑﺪءت اﻟﺒﺮﻣﺠﮫ واﻻﺣﺘﺮاف ﻛﻠﻤﺔ ﻟﺘﻤﯿﯿﺰ ﻗﺪرات اﻟﺸﺨﺺ ﻋﻠﻰ‬
‫اﻻﺑﺘﻜﺎر واﻟﺘﻔﻜﯿــــــــﺮ‬
‫واﻷﺑﺪاع وھﻲ ﻓﻲ اﻟﻨﮭﺎﯾﺔ ﺗﻔـــــﺎوت ﻓﻲ اﻟﻤﺴﺘﻮﯾﺎت وﻟﻜﻨﮭﺎ ﻟﯿﺴﺖ ﺑﺪرﺟﺔ اﻟﻜﻤﺎل ﻷن اﻟﻜﻤﺎل ﷲ وﺣﺪه‬

‫ﺳﺒﺤﺎﻧﮫ وﺗﻌﺎﻟــــــــــــﻰ‬
‫ﻓﺎﻟﺒﺮﻣﺠﺔ ﺑﺄﻋﺘﻘﺎدي اﻟﺸﺨﺼﻲ ﺑﺤﺮ ﺷﺎﺳﻊ ﻻ ﺣﺪوده ﻟﮫ ﻟﺘﻨﻮﻋﮭﺎ ‪ ..‬ﻓﺮﺑﻤﺎ اﻟﻤﺒﺘﺪء ﯾﺠﺪ ﻓﯿﮭﺎ ﻣﺎ ﯾﺘﻮﻗﻒ‬
‫ﻋﻨﺪه اﻟﻤـــــﺤﺘﺮف‬
‫وھﺬا ھﻮ ﻟﺐ اﻟﻤﻮﺿﻮع‬
‫اﻟﺘﻌﺎون ﺑﺄﻗﻞ ﻣﻌﻠﻮﻣﺔ ھﻮ اﻻﺣﺘﺮاف ﺑﺤﺪ ذاﺗﮫ‬

‫ﻣﺘﻄﻠﺒﺎت اﻟﻤﺸﺮوع‬
‫]‪[1‬ﺑﺮﻧﺎﻣﺞ ‪Visual Studio .NET‬‬
‫]‪[2‬ﻣﻌﺮﻓﺔ ﻣﺴﺒﻘﺔ ﺑﻠﻐﺔ اﻟﻔﯿﺠﻮل ﺑﯿﺴﻚ دوت ﻧﺖ واﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻧﻤﺎذﺟﮫ وأداوﺗﮫ‬
‫]‪[3‬ﻗﺎﻋﺪة ﺑﯿﺎﻧﺎت )وھﻨﺎ ﺳﻨﺒﺪأ ﻣﻊ اﻷﻛﺴﺲ ﺛﻢ ﺳﻨﺤﻮﻟﮭﺎ إﻟﻰ ﻗﺎﻋﺪة ﺳﯿﺮﻓﺮ وﺳﻨﺮى اﻻﺧﺘﻼف)‬
‫]‪[4‬ﻋﻠﯿﻚ ﺑﻜﺘﺎﺑﺔ اﻟﺸﯿﻔﺮات اﻟﻤﻮﺟﻮدة ﻓﻲ اﻟﺪرس ﻟﻜﻲ ﺗﺨﻄﻰء وﺗﻌﺮف أﯾﻦ أﺧﻄﺄت‬

‫ﻣﻼﺣﻈﺔ ‪ :‬اﺗﻤﻨﻰ ﻣﻦ اﻻﺧﻮة اﻻﻋﻀﺎء ﻋﻨﺪ أدراﺟﻜﻢ ﻟﻤﺸﺎرﻛﺎﺗﻜﻢ أن ﺗﻘﺘﺼﺮ ﻋﻠﻰ اﻷﺳﺌﻠﺔ واﻷﺳﺘﻔﺴﺎرات ﺑﻌﻜﺲ اﻟﻤﺪح واﻟﺸﻜﺮ ‪..‬‬
‫ﻓﻜﻞ ﻣﺎﻧﺮﯾﺪه ھﻮ اﻷﻓﺎدة واﻷﺳﺘﻔﺎدة وﻋﺪم أﻛﺜﺎر اﻟﺼﻔﺤﺎت ﺑﺪون ﻓﺎﺋﺪة ‪ ..‬وﻣﻦ ﯾﺮﯾﺪ أﺑﺪء أﻋﺠﺎﺑﮫ أو أﻧﺘﻘﺎده ﻟﻠﻤﻮﺿﻊ أن ﯾﺮاﺳﻠﻨﻲ‬
‫ﺑﺮﺳﺎﻟﺔ ﻋﻠﻰ اﻟﺨﺎص‪.‬‬

‫ﻧﺒﺬه ﻋﻦ‪ADO.NET‬‬
‫ھﻲ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻔﺌﺎت ﻣﺸﻤﻮﻟﺔ ﻓﻲ ﻣﺠﺎل اﻷﺳﻤﺎء ‪ System.Data‬ﻏﺮﺿﮭﺎ اﻟﻮﺻﻮل إﻟﻰ ﻣﺼﺎدر‬
‫اﻟﺒﯿﺎﻧﺎت ‪Data Sources‬واﻟﺘﻲ ﺗﻤﺜﻞ ﺑﯿﺎﻧﺎت ﻣﺤﻔﻮﻇﺔ ﺗﺤﺖ أﻧﻈﻤﺔ ﻗﻮاﻋﺪ ﺑﯿﺎﻧﺎت ﻣﺘﻌﺪدة اﻷﻧﻮاع‬
‫ﻣﻤﺎ ﯾﻌﻨﻲ ﻗﺪرﺗﻚ ﻋﻠﻰ اﻟﻮﺻﻮل إﻟﻰ أي ﻗﺎﻋﺪة ﺑﯿﺎﻧﺎت ﻣﮭﻤﺎ ﻛﺎﻧﺖ اﻟﺸﺮﻛﺔ اﻟﻤﻨﺘﺠﺔ ﻟﮭﺎ‬
‫(أ‪ .‬ﺗﺮﻛﻲ اﻟﻌﺴﯿﺮي )‬

‫اﻷﺧﺘﻼﻓﺎت اﻟﺠﻮھﺮﺑﺔ ﺑﯿﻦ ‪ADO.NET and ADO‬‬

‫** ‪** ADO‬‬
‫‪-1‬ﻣﺼﻤﺔ ﻟﻠﻌﻤﻞ ﻓﻲ ﺑﯿﺌﺔ ﻣﺘﺼﻠﺔ ﺑﺄﺳﺘﻤﺮار ﻣﻊ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت‬
‫‪-2‬ﯾﺴﺘﺨﺪم اﻟﻜﺎﺋﻦ ‪ RecordSet‬ﻟﻸﺣﺘﻔﺎظ ﺑﻤﺠﻤﻮﻋﺔ ﺑﯿﺎﻧﺎت واﺣﺪة‬

‫‪-3‬ﺗﺤﺘﻮي ﻋﻠﻰ أﻧﻮاع ﻣﻦ اﻟﻤﺆﺷﺮات ‪ Cursors‬اﻟﻤﺴﺘﺨﺪﻣﺔ ﻷﻏﺮاض ﻣﺨﺘﻠﻔﺔ وﻟﻜﻞ ﻣﺆﺷﺮ أﻣﻜﺎﻧﯿﺎﺗﮫ‬
‫اﻟﺨﺎﺻﺔ‬
‫‪-4‬ﺗﺨﺰن اﻟﺒﯿﺎﻧﺎت ﻓﻲ ھﯿﺌﺘﮭﺎ اﻟﺜﻨﺎﺋﯿﺔ ﻣﻤﺎ ﯾﺼﻌﺐ أرﺳﺎﻟﮭﺎ ﻋﺒﺮ ﺟﺪران اﻟﺤﻤﺎﯾﺔ ‪ .‬ﻛﻤﺎ أﻧﮭﺎ ﻏﯿﺮ ﻣﻔﯿﺪة‬
‫ﻟﻸﻧﻈﻤﺔ اﻟﺘﻲ ﻻ ﺗﺪﻋﻢ‪ADO‬‬
‫‪-5‬ﺗﺴﺘﮭﻠﻚ ﻗﺪرًا ﻣﻦ ﻣﻮارد اﻟﻨﻈﺎم ﺑﺴﺒﺐ اﺗﺼﺎﻟﮭﺎ اﻟﺪاﺋﻢ ﺑﻘﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت أﺛﻨﺎء اﻟﻤﻌﺎﻟﺠﺔ‬

‫** ‪** ADO.NET‬‬
‫‪-1‬ﻣﺼﻤﻤﺔ ﻣﻦ اﻷﺳﺎس ﻟﻠﻌﻤﻞ ﻓﻲ ﺑﯿﺌﺔ ﻏﯿﺮ ﻣﺘﺼﻠﺔ( وﯾﻤﻜﻨﮭﺎ اﻟﻌﻤﻞ ﺑﺎﺗﺼﺎل داﺋﻢ ﻣﻊ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت)‬
‫‪-2‬ﯾﺴﺘﺨﺪم اﻟﻜﺎﺋﻦ ‪ DataSet‬ﻟﻸﺣﺘﻔﺎظ ﺑﻌﺪة ﻣﺠﻤﻮﻋﺎت ﻣﻦ اﻟﺒﯿﺎﻧﺎت‬
‫‪-3‬ﻻ ﺗﺴﺘﺨﺪم اﻟﻤﺆﺷﺮات ﻷﻧﮭﺎ ﺗﻌﻤﻞ ﻓﻲ ﺑﯿﺌﺔ ﻏﯿﺮ ﻣﺘﺼﻠﺔ‪.‬‬
‫‪-4‬ﺗﺨﺰن اﻟﺒﯿﺎﻧﺎت ﻓﻲ ھﯿﺌﺔ ‪ XML‬اﻟﻌﺎﻟﻤﯿﺔ ‪ .‬وھﺬه اﻟﮭﯿﺌﺔ ﻣﺼﻤﻤﺔ ﻟﻜﻲ ﺗﺮﺳﻞ ﻋﺒﺮ ﺟﺪران اﻟﺤﻤﺎﯾﺔ‬
‫وﻋﺒﺮ اﻟﺸﺒﻜﺎت دون ﻣﺸﺎﻛﻞ ﻛﻤﺎ ﯾﻤﻜﻦ ﻷي ﺗﻄﺒﯿﻖ ﻗﺮاءة اﻟﺒﯿﺎﻧﺎت ﺑﮭﯿﺌﺔ ‪ XML‬ﺑﺴﮭﻮﻟﺔ‪.‬‬
‫‪-5‬ﺗﻌﻤﻞ ﻛﻨﻈﺎم ﺑﯿﺎﻧﺎت ﻣﻨﻔﺼﻞ ﻋﻦ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت ﻓﮭﻲ ﻻ ﺗﺘﺼﻞ ﺑﻘﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت إﻻ ﻋﻨﺪ اﻟﻀﺮورة‬
‫وﺑﺎﻟﺘﺎﻟﻲ ﻟﻦ ﺗﺴﺘﮭﻠﻚ ﻣﻮرد اﻟﻨﻈﺎم اﻹ ﻋﻨﺪ اﻟﻀﺮورة‬

‫واﻷﺧﺘﻼﻓﺎن اﻷﺧﯿﺮان رﻗﻢ ‪ 4 - 5‬ھﻤﺎ ﺟﻮھﺮة اﻻﺧﺘﻼف وأھﻤﮭﺎ‬

‫ﻣﻌﻤﺎرﯾﺔ‪ADO.NET‬‬
‫واﻟﻤﻘﺼﻮد ھﻨﺎ اﻟﺨﺼﺎﺋﺺ اﻟﻤﺰوده واﻟﻤﺴﺎﻋﺪة ﻓﻲ ﻋﻤﻠﯿﺔ اﻻﺗﺼﺎل ﻟﻘﺮاءة وﺗﻜﯿﯿﻒ اﻟﺒﯿﺎﻧﺎت وھﻲ‬
‫]‪[1‬ﻣﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت‪DataSet‬‬‫وھﻮ اﻟﻜﺎﺋﻦ اﻟﻤﻜﺎﻓﻰء ﻟﻠﻜﺎﺋﻦ ‪ RecordSet‬وﻟﻜﻦ ﻣﻊ اﻟﻜﺜﯿﺮ ﻣﻦ اﻟﻤﺰاﯾﺎ واﻟﺘﺤﺴﯿﻨﺎت ﺣﯿﺚ ﯾﺴﺘﻄﯿﻊ‬
‫ﺗﺨﺰﯾﻦ أﻛﺜﺮ ﻣﻦ ﺟﺪول أو ﻧﺘﯿﺠﺔ أﺳﺘﻌﻼم ﻓﻲ ﻧﻔﺲ اﻟﻮﻗﺖ ﺣﯿﺚ ﯾﻤﺜﻞ ﻛﻞ واﺣﺪ ﻣﻦ ھﺬه اﻟﺠﺪاول ﻛﺎﺋﻨ ًﺎ‬

‫ﻣﻨﻔﺼﻼً ﻋﻦ اﻵﺧﺮ‬

‫]‪[2‬ﻣﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت ‪DataAdapter‬‬‫ﯾﻤﺜﻞ اﻟﺠﺴﺮ اﻟﺬي ﯾﺮﺑﻂ ﺑﯿﻦ ‪ DataSet‬وﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت وﯾﺪﻋﻢ أواﻣﺮ ‪Select - Update -‬‬
‫‪Delete - Insert‬وﺑﺎﻟﺘﺎﻟﻲ ﺑﺈﻣﻜﺎﻧﮫ اﻟﻘﯿﺎم ﺑﻌﻤﻠﯿﺎت ﻣﺨﺘﻠﻔﺔ ﻋﻠﻰ اﻟﺒﯿﺎﻧﺘﺎ ﻛﻤﺎ أﻧﮫ اﻟﻤﺴﺆول ﻋﻦ‬
‫ﺗﺤﻤﯿﻞ ﻛﺎﺋﻦ ‪DataSet‬ﺑﺎﻟﺒﯿﺎﻧﺎت‬

‫]‪[3‬ﻣﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت ‪DataReader‬‬‫ﯾﺴﺘﺨﺪم ھﺬا اﻟﻜﺎﺋﻦ ﻟﻘﺮاءة اﻟﺒﯿﺎﻧﺎت ﻓﻘﻂ وﯾﻤﻜﻨﮫ ﻗﺮاءة ﻛﻤﯿﺎت ﺿﺨﻤﮫ ﻣﻨﮭﺎ ﺗﻠﻚ اﻟﺘﻲ ﻻ ﯾﻤﻜﻦ ﺗﺨﺰﯾﻨﮭﺎ‬
‫ﻓﻲ اﻟﺬاﻛﺮة ﻣﺆﻗﺘﺎً‬

‫]‪[4‬ﻣﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت ‪DataRelation‬‬‫ﯾﺴﺘﺨﺪم ھﺬا اﻟﻜﺎﺋﻦ ﻟﺘﻤﺜﯿﻞ اﻟﻌﻼﻗﺎت ﺑﯿﻦ اﻟﺠﺪاول ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت‪JOIN‬‬

‫]‪[5‬ﻣﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت ‪Connection‬‬‫ﯾﻌﻤﻞ ھﺬا اﻟﻜﺎﺋﻦ ﺑﺼﻮرة ﻣﺸﺎﺑﮭﺔ ﻟﻠﻜﺎﺋﻦ ‪ Connection‬ﻓﻲ ‪ ADO‬وھﻮ ﯾﻤﻜﻨﻨﺎ ﻣﻦ إﻧﺸﺎء اﺗﺼﺎل‬
‫ﻣﻊ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت‬

‫]‪[6‬ﻣﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت‪Command‬‬‫ﯾﺴﻤﺢ ھﺬا اﻟﻜﺎﺋﻦ ﻟﻜﺎﺋﻦ ‪ DataAdapter‬ﺑﺘﻄﺒﯿﻖ اﻷواﻣﺮ ﻋﻠﻰ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت وﯾﻤﻜﻨﮫ أن ﯾﺘﻀﻤﻦ‬
‫ارﺑﻌﺔ ﻣﻦ ھﺬه اﻷواﻣﺮ‬

‫ﻷﺿﺎﻓﺔ أﺳﺘﻔﺴﺎر أو ﺳﺆال ﺣﻮل اﻟﻤﻮﺿﻮع ﻣﻦ ھﻨﺎ‬

‫اﻟﺪرس اﻟﺘﺎﻟﻲ ﻓﻲ ﻋﻤﻠﯿﺔ اﻻﺗﺼﺎل ﺑﻘﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت وﻛﯿﻒ ﯾﺘﻢ ذﻟﻚ‬

‫*****************‬
‫ﻟﺨﺪﻣﺎت ﺗﺼﻤﯿﻢ وﺑﺮﻣﺠﺔ اﻟﻤﻮاﻗﻊ‬
‫‪programmer4ever@yahoo.com‬‬
‫‪00201063879624‬‬
‫************************‬

‫اﻟﺪرس اﻟﺜﺎﻧﻲ ‪ :‬ﻋﻤﻠﯿﺔ اﻻﺗﺼﺎل ﺑﺎﻟﻘﺎﻋﺪة‬

‫ﺗﺘﻄﻠﺐ ﻋﻤﻠﯿﺔ اﻟﻮﺻﻮل إﻟﻰ اﻟﺒﯿﺎﻧﺎت ﻣﻦ ﺧﻼل ‪ ADO.NET‬ﻋﻠﻰ ﻧﻮع ﻣﺼﺪر اﻟﺒﯿﺎﻧﺎت اﻟﺬي ﺗﻮد اﻻﺗﺼﺎل ﻣﻌﮫ ﺑﺎﻟﺘﺼﺮﯾﺢ‬
‫ﻋﻦ ﻣﺰود اﻟﺒﯿﺎﻧﺎت ﻟﻮ ﻓﺮﺿﻨﺎ أﻧﻨﺎ ﻧﺴﺘﺨﺪم ﻋﻤﻠﯿﺔ اﻻﺗﺼﺎل ﺑﺎﻟﻜﻮد‬
‫ﻛﻮد‬
‫)‪Dim cn As New OleDbConnection(connString‬‬
‫)(‪cn.Open‬‬
‫)‪Dim rs As New OleDbDataAdapter("SELECT * FROM [ Table]", cn‬‬
‫)(‪Dim rs As New DataSet‬‬
‫)"‪rs.Fill(rs, "Table‬‬

‫وﺳﻨﺄﺗﻲ ﻋﻠﻰ ﺷﺮح ﻣﺎ ﺳﺒﻖ ﺑﺘﻔﺼﯿﻞ ﺣﯿﺚ ﺳﺄذﻛﺮ اوﻻ ﻃﺮﯾﻘﺔ اﻻﺗﺼﺎل ﺑﻮاﺳﻄﺔ اﻟﻤﻌﺎﻟﺞ ﻷن ھﺪﻓﻲ اﻻﺳﺎﺳﻲ ﺗﻮﺿﯿﺢ‬
‫اﻟﻤﺴﺄﻟﺔ ﺑﺄﻛﺒﺮ ﻗﺪر ﻣﻦ اﻟﻤﻌﻠﻮﻣﺎت ﻛﻤﺎ ﯾﻠﻲ‬

‫اﻟﺨﻄﻮةاﻷوﻟﻰ ‪ :‬أﻧﺸﺎء ﻛﺎﺋﻦ ‪ DataAdapter‬ﺑﻮاﺳﻄﺔ اﻟﻤﻌﺎﻟﺞ ﻓﻲ‪2002 - 2003‬‬
‫ﺣﯿﺚ ﺳﺘﻘﻮم ﺑﺘﺤﺪﯾﺪ اﻟﻜﺎﺋﻦ ‪ OleDbDataAdapter‬ﺛﻢ ﻗﻢ ﺑﺮﺳﻤﮫ ﻋﻠﻰ اﻟﻔﻮرم اﻣﺎ ﻓﻲ ‪ 2005‬ﺗﻢ ﺗﺤﺪﯾﺪ ھﺬا اﻟﻜﺎﺋﻦ ﻣﻦ‬
‫ﻗﺎﺋﻤﺔ‪Data ---> Add New Data Source‬‬

‫اﻟﺨﻄﻮة اﻟﺜﺎﻧﯿﺔ ‪ :‬ﺗﺤﺪﯾﺪ اﻟﻤﺰود ﺛﻢ ﺗﺤﺪﯾﺪ ﻣﺼﺪر اﻟﺒﯿﺎﻧﺎت اﻟﺬي ﺗﻮد اﻻﺗﺼﺎل ﻣﻌﮫ ﻋﻦ ﻃﺮﯾﻖ اﻧﺸﺎء اﺗﺼﺎل ﺟﺪﯾﺪ ‪New‬‬
‫‪Connection‬‬

‫ﺛﻢ ﻧﺨﺘﺎر ‪ ..‬ﺗﺒﻮﯾﺐ اﻟﻤﻮﻓﺮ ﻟﺘﺤﺪﯾﺪ اﻟﻤﺰود‬

‫ﺣﯿﺚ ﺳﻨﺤﺪد اﻟﻤﺰود اﻟﺨﺎص ﺑﺎﻻﻛﺴﺲ وﺑﺈﻣﻜﺎﻧﻚ اﺧﺘﯿﺎر اﻟﻤﺰود اﻟﺨﺎص ﺑـ ‪SQL‬‬

‫ﻓﻲ‪2005‬‬

‫ﺛﻢ ﻗﻢ ﺑﺎﻟﻀﻐﻂ ﻋﻠﻰ زر اﺧﺘﺒﺎر اﻻﺗﺼﺎل‪ Test Connection‬ﻷﺧﺘﺒﺎر اﻻﺗﺼﺎل‬

‫اﻟﺨﻄﻮة اﻟﺜﺎﻟﺜﺔ‪ :‬ﻛﺘﺎﺑﺔ اﻻﺳﺘﻌﻼم ‪ SQL‬اﻟﺬي ﯾﺤﺪد اﻟﺒﯿﺎﻧﺎت ﻛﻤﺎ ﺳﯿﺄﺗﻲ‬

‫أﻣﺎ ﻓﻲ ‪ ٢٠٠٥‬ﺗﺘﻢ اﻟﻌﻤﻠﯿﺔ ﺗﻠﻘﺎﺋﯿًﺎ‬

‫وأﺧﯿﺮا ﺳﯿﻈﮭﺮ إﻃﺎر أﺧﯿﺮ ﯾﺒﯿﻦ ﻓﯿﮫ اﻟﻌﻤﻠﯿﺎت اﻟﺘﻲ ﺗﻤﺖ وﺗﻮﻟﯿﺪ أواﻣﺮ اﻷﺿﺎﻓﺔ واﻟﺘﺤﺪﯾﺚ واﻟﺘﻌﺪﯾﻞ واﻟﺤﺬف وﻧﻔﺲ اﻟﺸﻲ‬
‫ﻣﻊ‪2005‬‬

‫ﺑﻌﺪ اﻻﻧﺘﮭﺎء ﻣﻦ اﻟﻤﻌﺎﻟﺞ ﺳﯿﻈﮭﺮ ﻟﻚ اﻟﻜﺎﺋﻨﺎن اﻟﺘﺎﻟﯿﯿﻦ ﺣﯿﺚ أن اﻟﻤﮭﺎﻟﺞ ﻗﺎم ﺑﺄﻧﺸﺎء ﻛﺎﺋﻦ اﻻﺗﺼﺎل ﺑﺎﻷﺿﺎﻓﺔ إﻟﻰ ﻛﺎﺋﻦ‬
‫‪OleDbDataAdapter1‬‬

‫*****************‬
‫ﻟﺨﺪﻣﺎت ﺗﺼﻤﯿﻢ وﺑﺮﻣﺠﺔ اﻟﻤﻮاﻗﻊ‬
‫‪programmer4ever@yahoo.com‬‬
‫‪00201063879624‬‬
‫************************‬

‫اﻷﺗﺼﺎل ﺑﻘﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت ﻋﻦ ﻃﺮﯾﻖ اﻷﻛﻮاد‪Connection‬‬

‫وھﺬه اﻟﻄﺮﯾﻘﺔ ھﻲ ﻣﺎ أﻓﻀﻠﮭﺎ داﺋﻤﺎ ‪ ..‬وﺳﺘﺠﺪ اﻟﻤﺘﻌﺔ ﻓﻲ ذﻟﻚ ﻣﻦ ﺧﻼل ﺗﺘﺒﻌﻚ ﻣﻌﻨﺎ ﻟﮭﺬه اﻟﺪروس‬
‫وﺳﻮف ﯾﺪور اﻟﻜﻼم ھﻨﺎ ﺣﻮل اﻻﺗﺼﺎل ﺑﻘﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت ﻣﻦ ﻧﻮع اﻛﺴﺲ ‪ Access‬وذﻟﻚ ﻷن اﻻﻏﻠﺒﯿﺔ‬
‫ﯾﺘﻌﺎﻣﻞ ﻣﻌﮭﺎ ﻓﻠﻨﺒﺪأ ‪...... .‬‬
‫ﻗﺒﻞ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻣﺼﺪر ﺑﯿﺎﻧﺎت‪ ،‬ﻋﻠﯿﻚ ﻓﺘﺢ اﺗﺼﺎل ﻣﻌﮭﺎ وﻓﻲ ھﺬا اﻟﻘﺴﻢ ﺳﻨﻌﺮض اﻻﺳﺎﻟﯿﺐ اﻟﻤﺘﻌﺪدة‬
‫ﻟﻼﺗﺼﺎل ﺑﻤﺼﺎدر اﻟﺒﯿﺎﻧﺎت‪.‬‬

‫ﺗﻌﺮﯾﻒ ﻛﺎﺋﻦ اﻻﺗﺼﺎل‬
‫ﻛﻮد‬
‫)(‪Dim Con As New OleDbConnection‬‬

‫ﺣﯿﺚ ‪ : OleDbConnection‬ﻣﺨﺼﺼﺔ ﻟﻸﺗﺼﺎل ﺑﻘﻮاﻋﺪ اﻟﺒﯿﺎﻧﺎت ﻣﻦ ﻧﻮع ‪OLE DB .NET‬‬
‫‪Data Provider‬أﻣﺎ أذا ﻛﺎﻧﺖ ﻗﻮاﻋﺪ اﻟﺒﯿﺎﻧﺎت ﻣﻦ ﻧﻮع ‪SQL Server .NET Data‬‬
‫‪Provider‬ﻓﺴﯿﻜﻮن ﺗﻌﺮﯾﻒ اﻻﺗﺼﺎل ﻣﻦ ﻧﻮع ‪ SqlConnection‬و ﺑﮭﺬا اﻟﺸﻜﻞ‪:‬‬
‫ﻛﻮد‬
‫)(‪Dim Con As New SqlConnection‬‬

‫ﻧﺺ اﻻﺗﺼﺎل ﺑﺎﻟﻘﺎﻋﺪة‬
‫ﺳﻮف ﻧﻘﻮم ﺑﺘﻌﺮﯾﻒ ﻣﺘﻐﯿﺮ ﻣﻦ ﻧﻮع ﻧﺺ ووﺿﻊ ﻣﺴﺎر اﻻﺗﺼﺎل ﺑﻘﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت ﺑﺪاﺧﻠﮫ ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ‬
‫ﻛﻮد‬
‫= ‪Dim ConnString As String‬‬
‫‪"Provider=Microsoft.Jet.OLEDB.4.0;Data Source‬‬
‫""‪=c:\HnHnDB.mdb‬‬

‫وھﺬ اﻟﻜﻮد ﯾﺠﺐ أﺳﻨﺎده إﻟﻰ ﻣﺰود اﻟﺒﯿﺎﻧﺎت اﻟﺬي ﯾﻤﯿﻞ ﻟﮫ ﻛﻤﺎ ﺳﺒﻖ ذﻛﺮه وھﻨﺎ ﺳﯿﺘﻢ اﺳﻨﺎده إﻟﻰ‬
‫‪OleDbConnection‬وﺳﺘﻜﻮن اﻟﺸﻔﺮة ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ‬
‫ﻛﻮد‬
‫‪Dim con As OleDbConnection‬‬
‫)‪con = New OleDbConnection(ConnString‬‬

‫أو ﯾﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ اﻟﺘﻌﺮﯾﻒ ﺑﮭﺬا اﻟﺸﻜﻞ اﯾﻀﺎ‬
‫ﻛﻮد‬
‫)‪Dim con As New OleDbConnection(ConnString‬‬

‫ﻣﻼﺣﻈﺔ ‪ :‬ﺑﺪﻻ ﻣﻦ ﻛﺘﺎﺑﺔ ﻧﺺ اﻻﺗﺼﺎل ﻛﺎﻣﻼ ﻓﻲ ﻛﻞ ﻣﺮة ﺗﻨﻮي اﻧﺸﺎء ﻛﺎﺋﻦ اﺗﺼﺎل ﺟﺪﯾﺪ ﻗﻢ ﺑﻮﺿﻊ ﻧﺺ‬
‫اﻻﺗﺼﺎل ﻓﻲ ﻣﺘﻐﯿﺮ ﻋﺎم ﻋﻠﻰ ﻣﺴﺘﻮى اﻟﻤﺸﺮوع‬
‫واﻟﻘﺼﺪ ان اﻟﻤﺘﻐﯿﺮ ﯾﺨﺘﺼﺮ ﻋﻠﯿﻚ ﻛﺘﺎﺑﺔ ﺷﻔﺮة اﻻﺗﺼﺎل ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ ﻓﻲ ﻛﻞ ﻣﺮة ﺗﺮﯾﺪ ﺑﮭﺎ اﻧﺸﺎء ﻛﺎﺋﻦ‬
‫ﻟﻸﺗﺼﺎل ﺑﺎﻟﻘﺎﻋﺪة ﻟﺘﺤﺪﯾﺚ ﺑﯿﺎﻧﺎﺗﮭﺎ‪.‬‬
‫ﻛﻮد‬
‫‪Dim con As New OleDbConnection‬‬
‫‪"Provider=Microsoft.Jet.OLEDB.4.0;Data Source‬‬
‫"‪=c:\HnHnDB.mdb‬‬

‫ﻼ واﻟﻘﺼﺪ ھﻨﺎ اﺳﺘﺨﺪام ‪App.Path‬‬
‫وﻟﺠﻌﻞ اﻟﻤﺴﺎر ﻟﻤﺠﻠﺪ اﻟﻘﺎﻋﺪة ﻣﻌﺮوف ﺗﻠﻘﺎﺋﯿﺎ ﻛﻤﺎ ﻓﻲ ‪ VB6‬ﻣﺜ ً‬
‫ﻓﻘﺪ ﺗﻐﯿﯿﺮت ﻛﻠﻤﺔ اﻟﻤﺴﺎر اﻟﺘﻠﻘﺎﺋﻲ ﻓﻲ اﻟﻔﯿﺠﻮل ﻧﺖ إﻟﻰ ‪ Application.StartupPath‬وھﻨﺎك‬
‫أﺷﻜﺎل ﻋﺪة ﻓﻲ اﺳﺘﺨﺮاج اﻟﻤﺴﺎرات ﻓﻲ اﻟﻔﯿﺠﻮل ﻧﺖ ﺳﻨﺬﻛﺮھﺎ ﻻﺣﻘ ًﺎ أﻧﺸﺎﷲ ‪ .‬وﺑﮭﺬه اﻟﻜﻠﻤﺔ ﺳﺘﻜﻮن‬
‫ﺷﻔﺮة اﻻﺗﺼﺎل ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ‬
‫ﻛﻮد‬
‫= ‪Dim ConnString As String‬‬
‫& "= ‪"Provider=Microsoft.Jet.OLEDB.4.0;Data Source‬‬
‫"‪Application.StartupPath & "\HnHnDB.mdb‬‬

‫ﻣﻼﺣﻈﺔ ‪ :‬ﯾﺠﺐ أن ﺗﻜﻮن ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت ‪ HnHnDB.mdb‬ﻓﻲ ﻣﺠﻠﺪ اﻟﻤﺸﺮوع ‪ Bin‬ﯾﻤﻜﻨﻚ وﺿﻊ‬
‫اﻟﻘﺎﻋﺪة ﻓﻲ اي ﻣﻜﺎن ﺗﺮﯾﺪ وﻟﻜﻦ اﻵن ﻧﺤﻦ ﻧﺘﻜﻠﻢ ﺣﻮل ﺧﺎﺻﯿﺔ ‪Application.StartupPath‬‬
‫واﻟﺘﻲ ﺗﻌﺮف ﻣﺴﺎر ھﺬا اﻟﻤﺠﻠﺪ ﻣﻦ ﺿﻤﻦ اﻟﻤﺸﺮوع‬

‫أﻣﺎ ﺑﺎﻟﻨﺴﺒﺔ ﻟﺸﻔﺮة اﻻﺗﺼﺎل ﺑﻘﺎﻋﺪة ﺑﯿﺎﻧﺎت ﻣﻦ ﻧﻮع ﺳﯿﺮﻓﺮ ‪ SQL Server‬وﺳﺘﻜﻮن ﺑﮭﺬا اﻟﺸﻜﻞ‬
‫وھﻲ ﻻ ﺗﺨﺘﻠﻒ ﻋﻦ اﻻﻛﺴﺲ ﺳﻮى ﻓﻲ ﻋﻤﻠﯿﺔ اﻻﺗﺼﺎل‬
‫ﺣﯿﺚ أﻧﻚ ﺳﺘﺘﻌﺎﻣﻞ ﻣﻊ ال ‪ Access‬ﻛﻤﻠﻒ ﻟﻘﺎﻋﺪة ﺑﯿﺎﻧﺎت اﻣﺎ ‪ SQL Server‬ﻓﺄﻧﻚ ﺗﺘﻌﺎﻣﻞ ﻣﻊ‬
‫ﻣﺤﺮك ﻗﻮاﻋﺪ ﺑﯿﺎﻧﺎت‬
‫ﻛﻮد‬

‫)(‪Dim SQLCon As New SqlConnection‬‬
‫‪SQLCon.ConnectionString = "Data‬‬
‫_ ";‪Source=DEV4ARABS_SERVER‬‬
‫‪& "User ID= HnHn ; Password= _ ";admin‬‬
‫" =‪& "Initial Catalog‬اﻟﻘـــﺎﻋﺪة‬

‫اﻵن ﺳﻨﺄﺗﻲ ﻋﻠﻰ ﻓﺘﺢ وإﻏﻼق اﻻﺗﺼﺎل ﺑﺎﻟﻘﺎﻋﺪة‬
‫ﺑﻌﺪ أن اﺳﻨﺪﻧﺎ ﻧﺺ اﻻﺗﺼﺎل ﺑﺎﻟﻘﺎﻋﺪة ﻟﻠﻤﺘﻐﯿﺮ ‪ ConnString‬ﯾﻤﻜﻨﻨﺎ اﻵن اﻟﺒﺪء ﺑﻔﺘﺢ اﻻﺗﺼﺎل‬
‫واﻏﻼﻗﮫ ﻋﻦ ﻃﺮﯾﻖ ھﺬه اﻟﺠﻤﻞ ‪...‬‬
‫ﻛﻮد‬
‫)( ‪con.Open‬ﻟﻔﺘﺢ اﻻﺗﺼﺎل‬
‫)( ‪con.Close‬ﻷﻏﻼق اﻻﺗﺼﺎل‬

‫وﻟﻤﻌﺮﻓﺔ ﺣﺎﻟﺔ اﻻﺗﺼﺎل ان ﻛﻨﺎ ﻣﺘﺼﻠﯿﻦ ﺑﺎﻟﻘﺎﻋﺪة أم ﻻ ﺳﻨﺴﺘﺨﺪم اﻟﺤﺎﻟﺔ ‪ State‬اﻟﺘﺎﺑﻌﺔ ﻟﻜﺎﺋﻦ اﻻﺗﺼﺎل‬
‫واﻟﺘﻲ ﺳﯿﻨﺘﺞ ﻋﻨﮭﺎ ﻋﻨﺪ اﻻﺳﺘﻔﺴﺎر ﻣﺎ ﯾﻠﻲ أن ﻛﺎن اﻻﺗﺼﺎل ﻓﻲ اﻻوﺿﺎع اﻟﺘﺎﻟﯿﺔ ‪:‬‬
‫‪[1] Open‬اﻻﺗﺼﺎل ﻣﻔﺘﻮح‬
‫‪[2]Closed‬اﻻﺗﺼﺎل ﻣﻐﻠﻖ‬
‫‪[3]Connecting‬ﺟﺎري ﻓﺘﺢ اﻻﺗﺼﺎل‬
‫‪[4]Executing‬ﯾﺘﻢ ﺗﻨﻔﯿﺬ اﻣﺮ اﺳﺘﻌﻼم ﻋﻠﻰ اﻻﺗﺼﺎل‬
‫‪[5] Fetching‬ﺟﺎري اﻟﺤﺼﻮل ﻋﻠﻰ ﺑﯿﺎﻧﺎت ﻣﻦ ﺳﺠﻼت ﻣﺼﺪر اﻟﺒﯿﺎﻧﺎت‬

‫وﺳﺘﺄﺗﻲ ﺷﻔﺮة اﻟﺘﺄﻛﺪ ﻣﻦ ﺣﺎﻟﺔ اﻻﺗﺼﺎل ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ‬
‫ﻛﻮد‬
‫‪If (Con.State And ConnectionState.Open) <> 0 Then‬‬
‫‪'HnHn‬اﻟﺘﻌﺮف إﻟﻰ ﺣﺎﻟﺔ اﻻﺗﺼﺎل‬

‫"(‪MsgBox‬ﺗﻢ ﻓﺘﺢ اﻻﺗﺼﺎل ﺑﻨﺠﺎح)"‬
‫‪Else‬‬
‫"(‪MsgBox‬ﺗﻢ اﻏﻼق اﻻﺗﺼﺎل)"‬
‫‪End If‬‬

‫وﯾﻤﻜﻨﻚ ﺗﻐﯿﯿﺮ اﻟﻮﺿﻊ ‪ Open‬إﻟﻰ إي ﻣﻦ اﻷوﺿﺎع اﻟﺴﺎﺑﻘﺔ‬

‫ﺳﻨﺄﺗﻲ اﻷن ﻋﻠﻰ ذﻛﺮ ﻛﺎﺋﻦ اﻷواﻣﺮ ‪Command‬‬
‫وﻟﺘﺬﻛﯿﺮ ﻓﻘﻂ ﺑﻤﺎ ﺳﺒﻖ ذﻛﺮه ﻋﻦ اﻟﻜﺎﺋﻦ‬
‫اﻗﺘﺒﺎس‬

‫]‪[6‬ﻣﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت‪ Command‬ﯾﺴﻤﺢ ھﺬا اﻟﻜﺎﺋﻦ ﻟﻜﺎﺋﻦ ‪ DataAdapter‬ﺑﺘﻄﺒﯿﻖ اﻷواﻣﺮ‬‫ﻋﻠﻰ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت‬

‫ﺑﻌﺪ ﺗﻜﻮﯾﻦ اﻻﺗﺼﺎل ﻣﻊ ﻗﺎﻋﺪ ة اﻟﺒﯿﺎﻧﺎت‪ ،‬ﺳﺘﺄﺗﻲ ھﺬه اﻟﺨﻄﻮة وھﻲ ارﺳﺎل ﺟﻤﻞ اﻻﺳﺘﻌﻼم وھﻨﺎ ﺑﺄﻣﻜﺎﻧﻚ‬
‫ﺣﺼﺮ اﻟﺒﯿﺎﻧﺎت اﻟﺘﻲ ﺗﺮﯾﺪ اﺳﺘﻌﺮاﺿﮭﺎ ﻛﻤﺎ ﺗﺸﺎء أن ﻛﺎﻧﺖ ﻟﺪﯾﻚ ﻓﻜﺮة ﻓﻲ ﺟﻤﻞ اﻻﺳﺘﻌﻼم ‪SQL‬‬
‫وﺳﺘﻜﻮن ھﺬه اﻟﺸﻔﺮة ﻣﻊ ﺷﻔﺮة اﻻﺗﺼﺎل وﺳﯿﻜﻮن ﺗﻌﺮﯾﻔﺎ ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ‬
‫ﻛﻮد‬
‫)(‪Dim cmd As New OleDbCommand‬‬

‫أﻣﺎ أذا ﻛﺎﻧﺖ ﻗﻮاﻋﺪ اﻟﺒﯿﺎﻧﺎت ﻣﻦ ﻧﻮع ‪ SQL Server .NET Data Provider‬ﻓﺴﯿﻜﻮن ﺗﻌﺮﯾﻒ‬
‫اﻻﺗﺼﺎل ﻣﻦ ﻧﻮع ‪ SqlConnection‬و ﺑﮭﺬا اﻟﺸﻜﻞ‪:‬‬
‫ﻛﻮد‬
‫)(‪Dimcmd As As New SqlCommand‬‬

‫وﺳﺘﻜﻮن ﺷﻔﺮة اﻟﺮﺑﻂ ﻣﻊ اﻻﺗﺼﺎل ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ‬
‫ﻛﻮد‬
‫‪'HnHn‬ﺷﻔﺮة اﻻﺗﺼﺎل ﺑﺎﻟﻘﺎﻋﺪة ﺑﺸﻜﻞ ﺗﺎم‬
‫)‪Dim Con As New OleDbConnection(ConnString‬‬

‫)(‪Dim cmd As New OleDbCommand‬‬
‫)(‪Con.Open‬‬
‫‪cmd.Connection = Con‬‬

‫ﺗﺎﺑﻊ ﻟﻌﻤﻠﯿﺔ اﻻﺗﺼﺎل( ﻓﺘﺢ اﻟﺠﺪاول واﻟﺘﻌﺎﻣﻞ ﻣﻌﮭﺎ)‬

‫ﺳﻨﺤﺘﺎج ھﻨﺎ إﻟﻰ ﻋﻨﺼﺮﯾﻦ رﺋﯿﺴﯿﯿﻦ ﻟﺘﻜﻤﻠﺔ ﻋﻤﻠﯿﺔ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺒﯿﺎﻧﺎت وھﻤﺎ ‪...‬‬
‫‪[1] - OleDbConnection‬‬
‫‪[2] - DataSet‬‬

‫وھﺬا ھﻮ ﺗﻌﺮﯾﻔﮭﻤﺎ ﻣﻊ اﻟﺘﻌﺎرﯾﻒ اﻟﺴﺎﺑﻘﺔ اﻟﻤﻮﺿﻮﻋﮫ ﻓﻲ ﺣﺪث‪Public Class Form1‬‬
‫وﺳﺘﺄﺗﻲ ﺑﺸﻜﻞ ھﺬا‬
‫ﻛﻮد‬
‫‪Dim Con As New OleDb.OleDbConnection() REM HnHn :‬‬
‫"ﺗﻌﺮﯾﻒ ﻛﺎﺋﻦ اﻻﺗﺼﺎل"‬
‫" ‪Dim cmd As New OleDbCommand() REM HnHn :‬ﺗﻌﺮﯾﻒ ﻛﺎﺋﻦ أﻣﺮ‬
‫ﻟﺘﻤﺮﯾﺮ اﻻﺳﺘﻌﻼم ﺛﻢ اﻻﺗﺼﺎل"‬
‫" ‪Dim Dp As OleDb.OleDbDataAdapter REM HnHn :‬ﺗﻌﺮﯾﻒ ﻛﺎﺋﻦ‬

‫ﺗﺪﻓﻖ اﻟﺒﯿﺎﻧﺎت ﺑﻤﻌﻨﻰ اﻟﻤﺼﺪر أو اﻟﻤﺰود"‬
‫" ‪Dim rs As New DataSet() REM HnHn :‬ﺗﻌﺮﯾﻒ ﻛﺎﺋﻦ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺒﯿﺎﻧﺎت‬
‫ﻓﻲ اﻟﺬاﻛﺮة"‬
‫" ‪'Dim ConnString As String REM HnHn :‬ﺗﻌﺮﯾﻒ ﻣﺘﻐﯿﺮ ﻟﺘﺨﺰﯾﻦ ﻣﺴﺎر‬
‫اﻟﻘﺎﻋﺪة"‬

‫وھﻜﺬا ﻧﻜﻮن ﻛﻮﻧﺎ اﻟﻤﺠﻤﻮﻋﺔ اﻷﺳﺎﺳﯿﺔ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺒﯿﺎﻧﺎت ﺑﺸﻜﻞ ﺗﺎم وﺳﻨﺒﺪأ اﻵن ﺑﺎﻻﺗﺼﺎل ﺑﺄﺣﺪى‬
‫ﺟﺪاول اﻟﻘﺎﻋﺪة‬

‫[ﻣﻼﺣﻈﺔ ]‪:‬‬
‫ان ﻛﺎﺋﻦ اﻻواﻣﺮ ‪ OleDbCommand‬ﻻ ﯾﺼﻞ إﻟﻰ ﻣﺼﺪر اﻟﺒﯿﺎﻧﺎت ﺑﺸﻜﻞ ﻣﺒﺎﺷﺮ واﻧﻤﺎ ﯾﻌﺘﻤﺪ ﻋﻠﻰ‬
‫ﻛﺎﺋﻦ اﻻﺗﺼﺎل واﻟﺬي ﺑﺪوره ﯾﺼﻞ إﻟﻰ ﻣﺼﺪر ﺑﯿﺎﻧﺎت ﻛﻤﺎ ﻓﻲ ھﺬه اﻟﺸﻔﺮة واﻟﻤﺬﻛﻮرة ﻟﺪﯾﻚ ﻓﻲ اﻟﻤﺜﺎل‬
‫اﻟﻤﺮﻓﻖ ﺳﺎﺑﻘﺎ ‪.‬‬
‫ﻛﻮد‬
‫)(‪con.Open‬‬
‫‪cmd.Connection = con‬‬
‫)(‪con.Close‬‬

‫وﻟﻸﺳﺘﻔﺎدة ﻣﻦ ﻛﺎﺋﻦ اﻷﻣﺮ ﻋﻠﯿﻨﺎ ﺑﻨﺎء ﺟﻤﻞ ة أﺳﺘﻌﻼم ﻣﻊ ﻣﺮاﻋﺎة ﻧﻮﻋﮭﺎ أن ﻛﺎﻧﺖ ﺟﻤﻠﺔ اﺳﺘﻌﻼﻣﯿﺔ‬
‫ﺗﻘﻠﯿﺪﯾﺔ أو ﺟﻤﻠﺔ ﺗﻨﻔﯿﺬﯾﺔ وﻟﻠﻤﻌﻠﻮﻣﯿﺔ ‪....‬‬
‫أن اﻟﺠﻤﻞ اﻻﺳﺘﻌﻼﻣﯿﺔ ھﻲ اﻟﺘﻲ ﻻ ﺗﺆﺛﺮ ﻋﻠﻰ ﺳﺠﻼت ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت واﻧﻤﺎ ﺗﻘﻮم ﺑﻘﺮاءة ﻣﺤﺘﻮﯾﺎﺗﮭﺎ‬
‫وﻧﺴﺘﺨﺪم ﻟﮭﺎ أﻣﺮ‪SELECT‬‬
‫أﻣﺎ اﻟﺠﻤﻞ اﻟﺘﻨﻔﯿﺬﯾﺔھﻲ ﺗﻠﻚ اﻟﺠﻤﻞ اﻟﺘﻲ ﺗﺤﺪث ﺗﻐﯿﯿﺮا ﻓﻲ ﺳﺠﻼت ﺟﺪاول اﻟﻘﺎﻋﺪة ﺑﺸﻜﻞ اﻟﺘﺎﻟﻲ‬
‫‪.DELETE‬أو ‪UPDATE ،INSERT INTO ،‬‬
‫وﻏﺎﻟﺒﺎ ﻣﺎ ﯾﺴﺘﺨﺪم ﻣﻊ اﻟﺠﻤﻞ اﻟﺘﻨﻔﯿﺬﯾﺔ أﻣﺮ ‪ ()ExecuteNonQuery‬وذﻟﻚ ﻛﻨﻮع ﻣﻦ اﻟﺤﺼﺮ ﻟﻌﺪد‬
‫اﻟﺴﺠﻼت اﻟﺘﻲ ﺗﺄﺛﺮت ﺑﺎﻟﻌﻤﻠﯿﺔ وﻣﺜﺎل ذﻟﻚ اﻟﻌﻤﻠﯿﺔ اﻟﺘﺎﻟﯿﺔ ‪..‬‬
‫ﻛﻮد‬

‫‪Dim SQL As String = "UPDATE Emp SET Slary = 5000‬‬
‫" ‪WHERE NoEmp = 10001‬‬
‫)‪Dim cmd As New OleDbCommand(SQL, con‬‬
‫)(‪cmd.ExecuteNonQuery‬‬

‫اﻷن ﺳﻨﺄﺗﻲ ﻋﻠﻰ ﻋﻤﻠﯿﺔ اﻻﺗﺼﺎل ﺑﺠﺪول اﻟﺒﯿﺎﻧﺎت وﺳﺤﺒﮭﺎ ﻣﻨﮫ ﺑﺸﻜﻞ اﻟﺘﺎﻟﻲ‬

‫ ]‪[1‬ﺳﻨﻘﻮم ﺑﺘﻌﺮﯾﻒ ﻣﺘﻐﯿﯿﺮ ﻟﻮﺿﻊ ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم ﺑﺪاﺧﻠﮫ ﻛﻤﺎ ﯾﻠﻲ‬‫ﻛﻮد‬
‫"‪Dim SQL As String = "SELECT * FROM HnHnEmp‬‬

‫ ]‪[2‬ﺳﻨﻘﻮم ﺑﻮﺿﻊ اﻻﺳﺘﻌﻼم ﻣﻊ اﻻﺗﺼﺎل ﻓﻲ ﻣﺤﻮل اﻟﺒﯿﺎﻧﺎت ‪OleDbDataAdapter‬‬‫ﻛﻮد‬
‫‪Dp = New OleDb.OleDbDataAdapter(SQL, Con‬‬

‫ ]‪[3‬ﺳﻨﻘﻮم ﺑﻨﻘﻞ اﻟﺒﯿﺎﻧﺎت ﻟﺘﻌﺎﻣﻞ ﻣﻌﮭﺎ ﻣﻦ دون اﺗﺼﺎل ﺑﻮﺿﻌﮭﺎ ﻓﻲ‪DataSet‬‬‫ﻛﻮد‬
‫)"‪Dp.Fill(rs, "HnHnEmp‬‬

‫ ]‪[4‬أﺧﯿﺮا ﺳﻨﻐﻠﻖ اﻟﻘﺎﻋﺪة ﻟﺘﻌﺎﻣﻞ ﻣﻌﮭﺎ ﻣﻦ دون اﺗﺼﺎل وﺳﺘﺼﺒﺢ اﻟﺸﻔﺮة ﺑﺸﻜﻞ ﻧﮭﺎﺋﯿﺎ ﺑﺸﻜﻞ اﻟﺘﺎﻟﻲ‬‫‪.....‬‬
‫ﻛﻮد‬

‫" ‪Con.ConnectionString = ConnString REM HnHn :‬اﻻﺗﺼﺎل‬
‫ﺑﻤﺴﺎر اﻟﻘﺎﻋﺪة"‬
‫‪Con.Open() REM HnHn :‬ﻓﺘﺢ اﻻﺗﺼﺎل‬

‫" ‪SQL = "SELECT * FROM HnHnEmp" REM HnHn :‬وﺿﻊ‬
‫‪Dp = New OleDb.OleDbDataAdapter(SQL, Con) REM HnHn :‬‬
‫"ﺗﺪﻓﻖ اﻟﺒﯿﺎﻧﺎت ﻣﻊ اﻻﺗﺼﺎل ﻓﻲ اﻟﻤﺘﺤﻮل"‬
‫" ‪Dp.Fill(rs, "HnHnEmp") REM HnHn :‬اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺳﺠﻼت اﻟﺠﺪول ﻓﻲ‬
‫اﻟﺪات ﺳﯿﺖ"‬
‫)(‪Con.Close‬‬

‫ﻟﻢ ﯾﺘﺒﻖ اﻵن ﺳﻮى أﻇﮭﺎر اﻟﺒﯿﺎﻧﺎت ﻓﻲ اﻟﺤﻘﻮل اﻟﻤﺨﺼﺼﺔ ﻟﮭﺎ وﺳﺘﺄﺗﻲ اﻟﻄﺮﯾﻘﺔ ﺑﺸﻜﻞ اﻟﺘﺎﻟﻲ‬
‫ﻛﻮد‬
‫)‪TextBox1.Text = rs.Tables("HnHnEmp").Rows(0).Item(0‬‬

‫وﺗﻔﺼﯿﻠﮭﺎ ﻛﻤﺎ ﯾﻠﻲ ‪.....‬‬

‫‪TextBox1.Text :‬اﻟﺤﻘﻞ اﻟﺬي ﺳﯿﺮﺗﺒﻂ ﻣﻊ اﻟﺤﻘﻞ ﻓﻲ اﻟﺠﺪول‬
‫‪rs.Tables("HnHnEmp"). :‬اﺳﻢ اﻟﺠﺪول اﻟﻤﺪرج ﻣﻨﮫ اﺳﻢ اﻟﺤﻘﻞ اﻟﻤﺮﺗﺒﻂ ﺑﺎﻟﺘﯿﻜﺲ ﺑﻮﻛﺲ‬
‫‪Rows(0). :‬ﺗﻤﺜﻞ اﻟﺼﻒ اﻟﺨﺎص ﺑﺎﻟﺤﻘﻞ اﻟﻤﺮﺗﺒﻂ وﻋﻨﺪ ﺗﻐﯿﯿﺮ اﻟﺮﻗﻢ اﻟﺬي ﺑﺪاﺧﻠﮫ ﯾﺘﻢ اﻻﻧﺘﻘﺎل ﻟﺴﺠﻞ‬
‫اﻟﺘﺎﻟﻲ واﻟﻌﻜﺲ‬
‫‪Item(0). :‬ﺗﻤﺜﻞ ﻋﻨﺼﺮ اﻟﻮﺻﻮل إﻟﻰ اﻟﻔﺌﺎت اﻟﻤﺤﻀﻮﻧﺔ ﻣﻦ اﻟﻜﺎﺋﻦ اﻟﺮﺋﯿﺴﻲ ‪DataSet‬‬
‫وھﻲ ﺧﺎﺻﯿﺔ اﻓﺘﺮاﺿﯿﺔ ﻟﻠﻜﺎﺋﻦ ‪ DataRow‬ﻟﺬا ﯾﻤﻜﻨﻚ ﺗﺠﺎھﻠﮭﺎ ان اردت ‪.‬‬

‫وھﻜﺬا ﻣﻊ ﺑﻘﯿﺔ اﻟﺤﻘﻮل ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ وﻓﻖ اﻟﻤﺜﺎل اﻟﻤﺮﻓﻖ‪....‬‬
‫ﻛﻮد‬
‫‪REM HnHn :‬اﻇﮭﺎر ﺑﯿﺎﻧﺎت اﻟﺠﺪوﻟﻔﻲ اﻟﺤﻘﻮل اﻟﻤﺨﺼﺼﺔ‬
‫)‪TextBox1.Text = rs.Tables("HnHnEmp").Rows(0).Item(0‬‬
‫)‪TextBox2.Text = rs.Tables("HnHnEmp").Rows(0).Item(1‬‬
‫)‪TextBox3.Text = rs.Tables("HnHnEmp").Rows(0).Item(2‬‬
‫)‪TextBox4.Text = rs.Tables("HnHnEmp").Rows(0).Item(3‬‬

TextBox5.Text = rs.Tables("HnHnEmp").Rows(0).Item(4)
TextBox6.Text = rs.Tables("HnHnEmp").Rows(0).Item(5)
TextBox7.Text = rs.Tables("HnHnEmp").Rows(0).Item(6)

‫ﻋﻤﻠﯿﺔ اﻟﺘﻨﻘﻞ ﺑﯿﻦ اﻟﺴﺠﻼت‬
‫ﻓﻲ ﺑﯿﺌﺔ اﻟﻨﺖ اﺧﺘﻠﻒ اﻷﻣﺮ واﺻﺒﺤﺖ ﻋﻤﻠﯿﺔ اﻟﺘﻨﻘﻞ ﺑﮭﺬا اﻟﺸﻜﻞ ﻟﻠﺴﺠﻞ اﻟﺘﺎﻟﻲ‬
‫ﻛﻮد‬
Me.BindingContext(rs.Tables("HnHnEmp")).Position += 1

‫وﻟﻠﺴﺠﻞ اﻟﺴﺎﺑﻖ‬
‫ﻛﻮد‬
Me.BindingContext(rs.Tables("HnHnEmp")).Position - =
1

‫واﻟﺴﺠﻞ اﻷول ﺳﯿﻜﻮن ﺑﮭﺬا اﻟﺸﻜﻞ‬
‫ﻛﻮد‬
Me.BindingContext(rs.Tables("HnHnEmp")).Position = 0

‫واﻟﺴﺠﻞ اﻷﺧﯿﺮ ﺳﯿﻜﻮن ﺑﮭﺬا اﻟﺸﻜﻞ‬
‫ﻛﻮد‬
Me.BindingContext(rs.Tables("HnHnEmp")).Position =
Me.BindingContext(rs.Tables("HnHnEmp")).Count - 1

‫وھﺬا ﺑﺸﻜﻞ ﻋﺎم وﻟﻜﻦ ﻓﻲ ﻣﺜﺎﻟﻨﺎ ﺳﯿﺘﻢ ﻋﻤﻞ اﻟﺘﻨﻘﻞ ﺑﯿﻦ اﻟﺴﺠﻼت ﺑﺎﻟﻄﺮﯾﻘﺔ اﻟﺘﺎﻟﯿﺔ‬

‫[ﺳﻨﻘﻮم ﺑﻮﺿﻊ ﻣﺘﻐﯿﯿﺮ ﻋﻠﻰ ﻣﺴﺘﻮى اﻟﻔﻮم وﺳﯿﻜﻮن ﻣﻦ ﻧﻮع رﻗﻢ ﻟﺘﺨﺰﯾﻦ ﻗﯿﻤﺔ او رﻗﻢ اﻟﺴﺠﻞ‬1] -

‫ﺑﺪاﺧﻠﮫ ﻛﻤﺎ ﯾﻠﻲ‬
‫ﻛﻮد‬
Dim Rec As Integer

‫[ﺳﻨﻘﻮم ﺑﻌﻤﻞ أﺟﺮاء ﺑﺄﺳﻢ‬2] ‫ ھﻲ اﻟﻤﺘﻐﯿﯿﺮ‬Rows(0) ‫وﺳﯿﺤﻮي اﻟﺴﺠﻼت اﻟﻤﺮﺗﺒﻄﺔ ﺑﺎﻟﺤﻘﻮل وﺳﺘﻜﻮن ﻗﯿﻤﺔ‬ViewRecord
‫اﻟﺬي ﻗﻤﻨﺎ ﺑﺘﻌﺮﯾﻔﮫ ﻟﻠﺴﺠﻼت ﺑﺸﻜﻞ ھﺬا‬Rec
‫ﻛﻮد‬
Rows(Rec)

‫وﺳﯿﻜﻮن اﻷﺟﺮاء ﺑﺸﻜﻞ ھﺬا‬
‫ﻛﻮد‬
Private Sub ViewRecord()
‫اﻇﮭﺎر ﺑﯿﺎﻧﺎت اﻟﺠﺪوﻟﻔﻲ اﻟﺤﻘﻮل اﻟﻤﺨﺼﺼﺔ‬REM HnHn :
TextBox1.Text =
rs.Tables("HnHnEmp").Rows(Rec).Item(0)
TextBox2.Text =
rs.Tables("HnHnEmp").Rows(Rec).Item(1)
TextBox3.Text =
rs.Tables("HnHnEmp").Rows(Rec).Item(2)
TextBox4.Text =
rs.Tables("HnHnEmp").Rows(Rec).Item(3)
TextBox5.Text =
rs.Tables("HnHnEmp").Rows(Rec).Item(4)
TextBox6.Text =
rs.Tables("HnHnEmp").Rows(Rec).Item(5)
TextBox7.Text =
rs.Tables("HnHnEmp").Rows(Rec).Item(6)
'HnHn : Total Record

Label9.Text = Rec & Space(2) & "OF" & Space(2) &
rs.Tables("HnHnEmp").Rows.Count
End Sub

‫[ﺳﻨﻘﻮم اﻵن ﺑﺘﻜﻮﯾﻦ ﻋﻤﻠﯿﺔ اﻟﺘﻨﻘﻞ ﻟﻠﺴﺠﻼت ﺑﺸﻜﻞ اﻟﺘﺎﻟﻲ‬3] ‫اﻟﺴﺠﻞ اﻟﺘﺎﻟﻲ‬
‫ﻛﻮد‬
Private Sub ButtonNavNext_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButtonNavNext.Click
REM HnHn : Next
Rec = Rec + 1
Call ViewRecord()
End Sub

‫اﻟﺴﺠﻞ اﻟﺴﺎﺑﻖ‬
‫ﻛﻮد‬
Private Sub ButtonNavPrevious_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButtonNavPrevious.Click
REM HnHn : Previous
Rec = Rec - 1
Call ViewRecord()
End Sub

‫اﻟﺴﺠﻞ اﻷول‬

‫ﻛﻮد‬
Private Sub ButtonNavFirst_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButtonNavFirst.Click
REM HnHn : First
Rec = 0
Call ViewRecord()
End Sub

‫اﻟﺴﺠﻞ اﻷﺧﯿﺮ‬
‫ﻛﻮد‬
Private Sub ButtonNavLast_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButtonNavLast.Click
REM HnHn : Last
Rec = rs.Tables("HnHnEmp").Rows.Count - 1
Call ViewRecord()
End Sub

: ‫وﻟﺘﻨﻘﻞ ﺑﺄﻛﺜﺮ أﻣﺎن ﺳﻨﻀﻊ ﺑﻌﺾ اﻟﺸﺮوط ﻟﺘﺤﻘﻖ ﻣﻦ اﻟﺴﺠﻞ أن ﻛﺎن ﻓﻲ اﻷول أو ﻓﻲ اﻷﺧﯿﺮ ﻛﻤﺎ ﯾﻠﻲ‬
‫اﻻﻧﺘﻘﺎل ﻟﺴﺠﻞ اﻟﺘﺎﻟﻲ‬
‫ﻛﻮد‬
Private Sub ButtonNavNext_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles

ButtonNavNext.Click
REM HnHn : Next
Rec = Rec + 1
‫'اﻟﺘﺤﻘﻖ ﻣﻦ اﻟﻤﺘﻐﯿﯿﺮ اذا ﻛﺎن اﻛﺒﺮ ﻣﻦ ﻣﺠﻤﻮع ﻋﺪد اﻟﺴﺠﻼت اﻟﻜﻠﻲ واﻋﺎدة ﺗﺨﺰﯾﻦ اﺧﺮ‬HnHn :
‫ﻗﯿﻤﺔ‬
If Rec > rs.Tables("HnHnEmp").Rows.Count - 1 Then
")‫ﻻ ﺗﻮﺟﺪ ﺳﺠﻼت ﻟﻸﻧﺘﻘﺎل إﻟﯿﮭﺎ‬MsgBox("
Rec = rs.Tables("HnHnEmp").Rows.Count - 1
Exit Sub
Else
Call ViewRecord()
End If
End Sub

‫اﻻﻧﺘﻘﺎل ﻟﺴﺠﻞ اﻟﺴﺎﺑﻖ‬
‫ﻛﻮد‬
Private Sub ButtonNavPrevious_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButtonNavPrevious.Click
REM HnHn : Previous
Rec = Rec - 1
‫'اﻟﺘﺤﻘﻖ ﻣﻦ اﻟﻤﺘﻐﯿﯿﺮ اذا ﻛﺎن اﻗﻞ ﻣﻦ اﻟﺼﻔﺮ واﻋﺎدة ﺗﺨﺰﯾﻦ اﺧﺮ ﻗﯿﻤﺔ‬HnHn :
If Rec < 0 Then
")‫ﻻ ﺗﻮﺟﺪ ﺳﺠﻼت ﻟﻸﻧﺘﻘﺎل إﻟﯿﮭﺎ‬MsgBox("
Rec = 0

‫‪Exit Sub‬‬
‫‪Else‬‬
‫)(‪Call ViewRecord‬‬
‫‪End If‬‬
‫‪End Sub‬‬

‫*****************‬
‫ﻟﺨﺪﻣﺎت ﺗﺼﻤﯿﻢ وﺑﺮﻣﺠﺔ اﻟﻤﻮاﻗﻊ‬
‫‪programmer4ever@yahoo.com‬‬
‫‪00201063879624‬‬
‫************************‬

‫ﻋﻤﻠﯿﺔ اﻷﺿﺎﻓﺔ واﻟﺘﺤﺪﯾﺚ‬
‫اﻷﺿﺎﻓﺔ‬

‫ﺳﺄﺗﺤﺪث ھﻨﺎ ﺑﻄﺮﯾﻘﺘﯿﻦ ﻷﺗﻤﺎم ﻋﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ وھﻤﺎ‬
‫]‪- [1‬اﺳﺘﻌﻤﺎل ﺧﺎﺻﯿﺔ ‪DataRow‬‬
‫]‪-[2‬اﺳﺘﻌﻤﺎل ﺟﻤﻠﺔ اﺳﺘﻌﻼم‪INSERT INTO‬‬

‫‪--‬‬‫‪DataRow‬‬
‫ﺣﯿﺚ اﻧﮭﺎ ﺗﻤﺜﻞ ﺳﺠﻞ ﻛﺎﻣﻞ ﻣﻦ ﺳﺠﻼت اﻟﺠﺪول وﻟﻦ ﻧﺴﺘﻄﯿﻊ اﻟﺘﻌﺎﻣﻞ ﻣﻌﮭﺎ ﺑﺈﻧﺸﺎء ﻛﺎﺋﻦ ﺑﺎﺳﺘﺨﺪام ‪New‬ﻣﻦ اﻟﻔﺌﺔ‬
‫‪DataRow‬ﺑﻤﻌﻨﻰ ان ﺗﻌﺮﯾﻒ اﻟﻤﺘﻐﯿﺮ ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ اﻟﺨﺎﻃﺌﺔ ﻟﻦ ﯾﻔﯿﺪ ﻓﻲ ﻋﻤﻠﯿﺔ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬
‫ﻛﻮد‬
‫‪Dim dRow As New DataRow‬‬

‫وأﻧﻤﺎ ﯾﺘﻢ ذﻟﻚ ﺑﻄﺮﯾﻘﺘﯿﻦ‪:‬‬
‫ ]‪[1‬ﺑﺘﻌﺮﯾﻒ ﺳﻄﺮ ﺟﺪﯾﺪ )(‪NewRaw‬‬‫‪[2] -‬ﺗﻌﺮﯾﻒ ﻣﺼﻔﻮﻓﺔ ﻣﻦ اﻟﻨﻮع‪Object‬‬

‫وﻟﻦ اﺷﺮح ﺳﻮى ﻃﺮﯾﻘﺘﯿﻦ ﻛﻤﺎ ذﻛﺮت ﺳﺎﺑﻘﺎ وھﻤﺎ اﻷﻛﺜﺮ اﺳﺘﺨﺪاﻣﺎ ﻓﻲ اﻋﺘﻘﺎدي واﯾﻀﺎ ﻟﻜﻲ ﻻ ﺗﺘﺸﻌﺐ اﻻﻣﻮر‬
‫ﺑﺘﻔﺎﺻﯿﻞ اﻛﺜﺮ ﺣﯿﺚ اﻧﻲ اﺣﺎول ان ارﻛﺰ ﻋﻠﻰ اﻻﻣﻮر اﻻﻛﺜﺮ ﻓﺎﺋﺪة وﺗﺪول وﻛﻠﻦ ﻟﮫ ﻃﺮﯾﻘﺘﮫ‪......‬‬
‫اذا ﺳﻨﺸﺮح‬
‫اﻟﻄﺮﯾﻘﺔ اﻷوﻟﻰ ﺑﺎﺳﺘﺨﺪام )(‪ NewRaw‬اﻟﺘﺎﺑﻌﺔ ﻟﻠﻔﺌﺔ ‪DataRow‬‬
‫ﻛﻮد‬
‫)(‪Dim dRow As DataRow = NameTabel.NewRow‬‬

‫ﻣﻼﺣﻈﺔ ‪ : NameTabel‬ھﻮ اﻟﺠﺪول )ﻣﺼﺪر اﻟﺒﯿﺎﻧﺎت )‬
‫وھﺬه ھﻲ ﺷﻔﺮة ﻋﻤﻠﯿﺔ أﺿﺎﻓﺔ ﺳﺠﻞ ﺑـﺎﻟﻔﺌﺔ ‪ DataRow‬واﻟﺨﺎﺻﯿﺔ )(‪NewRaw‬‬
‫ﻛﻮد‬
‫‪REM : HnHn‬ﻛﺎﺋﻦ ﻟﻺﺿﺎﻓﺔ ﺳﻄﺮ ﺟﺪﯾﺪ ﻟﻤﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت‬
‫‪Dim dRow As DataRow‬‬

‫‪REM : HnHn‬اﺿﺎﻓﺔ ﺳﻄﺮ ﺟﺪﯾﺪ ﻓﻲ اﻟﺠﺪول ﻟﺘﺨﺰﯾﻦ اﻟﺒﯿﺎﻧﺎت ﻓﯿﮫ‬
‫)(‪dRow = rs.Tables("HnHnEmp").NewRow‬‬

‫‪REM : HnHn :‬ﻋﻤﻠﯿﺔ ﻧﻘﻞ اﻟﺒﯿﺎﻧﺎت ﻣﻦ اﻟﺤﻘﻮل إﻟﻰ ﺣﻘﻮل اﻟﺠﺪول‬
‫'أﻣﺎ ﻋﻦ ﻃﺮﯾﻖ ﺗﺤﺪﯾﺪ اﺳﻤﺎء اﻟﺤﻘﻮل اﻟﺘﻲ ﻓﻲ اﻟﺠﺪول إو ﻋﻦ ﻃﺮﯾﻖ اﻟﻔﮭﺮﺳﺔ‬

‫‪REM : HnHn : dRow.Item("LastName") = TextBox2.Text‬‬
‫‪REM : HnHn : OR Index‬‬
‫‪dRow.Item(1) = TextBox2.Text‬‬
‫‪dRow.Item(2) = TextBox3.Text‬‬
‫‪dRow.Item(3) = TextBox4.Text‬‬
‫‪dRow.Item(4) = TextBox5.Text‬‬
‫‪dRow.Item(5) = TextBox6.Text‬‬
‫‪dRow.Item(6) = TextBox7.Text‬‬

‫اﻟﻄﺮﯾﻘﺔاﻟﺜﺎﻧﯿﺔ ﺑﺎﺳﺘﺨﺪام‬

‫‪INSERT INTO‬‬
‫ﺟﻤﻞ ال ‪ SQL‬ھﻲ اﺣﺪى ﻃﺮق ﻋﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ وﺳﺘﻜﻮن ﺷﻔﺮة اﻻﺿﺎﻓﺔ ﻣﺴﻨﻮدة إﻟﻰ ﻣﺘﻐﯿﺮ ﻣﻦ ﻧﻮع ﻛﻮﻣﺎﻧﺪ‬
‫‪OleDbCommand‬وﻗﺪ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ أن ھﺬه اﻟﻔﺌﺔ ﺗﺆدي ﻣﮭﻤﺔ ﺗﻄﺒﯿﻖ اﻻواﻣﺮ ﻋﻠﻰ اﻟﻘﺎﻋﺪة وھﺎ ﻧﺤﻦ‬
‫ﻧﺴﺘﺨﺪﻣﮭﺎ اﻵن ﻓﻲ ﺗﻄﺒﯿﻖ ﺟﻤﻠﺔ ‪ SQL‬ﻣﻦ آﺟﻞ ﻋﻤﻠﯿﺔ اﻷﺿﺎﻓﺔ ﺣﯿﺚ ﺳﻨﺤﺘﺎج ﻣﻨﮭﺎ اﻟﻌﻨﺼﺮ‬
‫‪CommandText‬وﺳﺘﻜﻮن اﻟﺸﻔﺮة ﻋﻠﻰ ﺳﺒﯿﻞ اﻟﻤﺜﺎل ﻛﻤﺎ ﯾﻠﻲ ‪..‬‬
‫ﻛﻮد‬
‫‪'Rem HnHn :‬ﺗﻌﺮﯾﻒ ﻣﺘﻐﯿﺮ واﺳﻨﺎده إﻟﻰ ﻛﻮﻣﺎﻧﺪ ﻟﯿﻘﻮم ﺑﻌﻤﻠﯿﺔ اﻟﺤﻔﻆ ﻟﺠﻤﻠﺔ اﻻﺿﺎﻓﺔ‬
‫‪Dim SavInto As New OleDb.OleDbCommand‬‬

‫‪REM HnHn : INSERT‬ﺟﻤﻠﺔ اﻻﺿﺎﻓﺔ ﺑـ‬
‫)‪SavInto.CommandText = "INSERT INTO HnHnEmp (NameField‬‬
‫" )'" & ‪values ('" & TextBox1‬‬

‫ﺣﯿﺚ = ‪ NameField‬ﺳﻨﻜﺘﺐ ﺑﺪﻻ ﻋﻨﮫ اﺳﻤﺎء اﻟﺤﻘﻮل اﻟﻤﻮﺟﻮدة ﻓﻲ اﻟﺠﺪول وﺗﻔﺼﻞ ﺑﯿﻨﮭﻤﺎ اﻟﻔﺎﺻﻠﺔ‬
‫)‪(,‬وﺳﻨﻜﺘﺐ ﻧﻈﯿﺮھﺎ ﻣﻦ اﻟﺤﻘﻮل اﻟﻠﻲ ﻋﻠﻰ اﻟﻔﻮرم ﺑﻨﻔﺲ اﻟﺘﺴﻠﺴﻞ ‪ TextBox2 , TextBox1‬وھﻜﺬا ‪...‬ﻣﻊ‬
‫ﻣﺮاﻋﺎة ﻋﻼﻣﺎت اﻟﺘﻨﺼﯿﺺ ' أذا ﻛﺎن اﻟﺤﻘﻞ ﻓﻲ اﻟﺠﺪول ﻣﻦ ﻧﻮع ﻧﺺ وﺑﺪون ﻋﻼﻣﺎت ﺗﻨﺼﯿﺺ أذا ﻛﺎن ﻧﻮع اﻟﺤﻘﻞ‬
‫رﻗﻢ وﻋﻼﻣﺔ ‪ #‬اذا ﻛﺎن ﻧﻮع اﻟﺤﻘﻞ ﺗﺎرﯾﺦ وﺑﻨﺎء ﻋﻠﻰ اﻟﻤﺜﺎل اﻟﻤﺮﻓﻖ ﻟﺪﯾﻜﻢ ﺳﻨﻜﺘﺐ اﻟﺸﻔﺮة ﻛﻤﺎ ﯾﻠﻲ ‪...‬‬
‫ﻛﻮد‬
‫‪'Rem HnHn :‬ﺗﻌﺮﯾﻒ ﻣﺘﻐﯿﺮ واﺳﻨﺎده إﻟﻰ ﻛﻮﻣﺎﻧﺪ ﻟﯿﻘﻮم ﺑﻌﻤﻠﯿﺔ اﻟﺤﻔﻆ ﻟﺠﻤﻠﺔ اﻻﺿﺎﻓﺔ‬
‫‪Dim SavInto As New OleDb.OleDbCommand‬‬

‫‪REM HnHn : INSERT‬ﺟﻤﻠﺔ اﻻﺿﺎﻓﺔ ﺑـ‬

‫‪SavInto.CommandText = "INSERT INTO HnHnEmp‬‬
‫‪(LastName,FirstName,BirthDate,Address,Mobail,Notes) values‬‬
‫& "‪('" & TextBox2.Text & "','" & TextBox3.Text & "',#‬‬
‫& "‪TextBox4.Text & "#,'" & TextBox5.Text & "',‬‬
‫" )'" & ‪TextBox6.Text & ",'" & TextBox7.Text‬‬

‫ﺗﺤﺪﯾﺚ اﻟﺒﯿﺎﻧﺎت‬

‫وھﻜﺬا ﻋﺮﺿﻨﺎ ﺛﻼﺛﺔ ﻃﺮق ﻟﻌﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ واﻟﻤﻮﺿﻮع ﻟﻢ ﯾﻨﺘﮭﻲ ﺑﻌﺪ ﺣﯿﺚ ﻻﺑﺪ ﻣﻦ ﺑﻌﺪ ﻋﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ ﺗﺄﺗﻲ ﻋﻤﻠﯿﺔ‬
‫ﺗﺤﺪﯾﺚ اﻟﺒﯿﺎﻧﺎت وھﺬا ﻣﺎ ﺳﻨﺸﺮﺣﮫ اﻵن ﻣﻊ ﻛﻞ ﻃﺮﯾﻘﺔ ﻣﻦ اﻟﻄﺮق اﻟﺴﺎﺑﻘﺔ ﻛﯿﻒ ﺳﯿﺘﻢ ﺗﺤﺪﯾﺚ اﻟﺒﯿﺎﻧﺎت ﻓﯿﮭﺎ وﺳﻨﺒﺪأ‬
‫ﺑــــــ‬

‫ﺗﺤﺪﯾﺚ ﺑﯿﺎﻧﺎت اﻟﻄﺮﯾﻘﺔ اﻷوﻟﻰ )(‪ : NewRaw‬اﻟﺨﺎﺻﺔ ﺑﺎﻟﻔﺌﺔ ‪DataRow‬‬

‫وﺳﺘﺄﺗﻲ ﻋﻤﻠﯿﺔ ﺗﺤﺪﯾﺚ اﻟﺒﯿﺎﻧﺎت ھﻨﺎ ﺑﺘﻌﺮﯾﻒ ﻣﺘﻐﯿﺮ ﻣﻦ ﻧﻮع اﻟﻔﺌﺔ ‪ DbCommandBuilder‬اﻟﺨﺎص‬
‫ﺑﺎﻟﻌﻤﻠﯿﺎت اﻟﺘﻲ ﺗﺤﺪث ﻋﻠﻰ اﻟﺴﺠﻼت ﻣﻦ ﺟﻤﻞ اﻻﺳﺘﻌﻼم ‪ SQL‬ﺛﻢ ﯾﺘﻢ اﺳﻨﺎد اﻟﻜﺎﺋﻦ ﻟﻠﻤﺤﻮل ‪DataAdapter‬‬
‫وﻣﻦ ﺛﻢ ﻓﺘﺢ اﻟﺠﺪول وأﺿﺎﻓﺔ ﺳﺠﻞ ﻓﯿﮫ ﻣﺪرج ﻓﻲ ﺣﻘﻮﻟﮫ اﻟﺒﯿﺎﻧﺎت اﻟﻤﺴﻨﺪه ﻟﮫ وﻣﻦ ﺛﻢ اﺳﻨﺎد اﻟﺴﺠﻞ ﺑﺤﻘﻮﻟﮫ‬
‫ﻟﻠﻤﺤﻮل ﻓﻲ ﻋﻤﻠﯿﺔ ﺗﺤﺪﯾﺚ ﻟﻠﺒﯿﺎﻧﺎت وﺗﺄﺗﻲ اﻟﺸﻔﺮة اﻟﻨﮭﺎﺋﯿﺔ ﻓﻲ ھﺬه اﻟﻤﺮﺣﻠﺔ ﻣﻦ ﻋﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ ﺑﮭﺬه اﻟﻄﺮﯾﻘﺔ ﻛﻤﺎ‬
‫ﯾﻠﻲ‪...‬‬
‫ﻛﻮد‬
‫)‪Dim CmdB As New OleDb.OleDbCommandBuilder(Dp‬‬
‫‪'-----------------------‬‬‫‪REM : HnHn‬ﻛﺎﺋﻦ ﻟﻺﺿﺎﻓﺔ ﺳﻄﺮ ﺟﺪﯾﺪ ﻟﻤﺠﻤﻮﻋﺔ اﻟﺒﯿﺎﻧﺎت‬
‫‪Dim dRow As DataRow‬‬

‫‪REM : HnHn‬اﺿﺎﻓﺔ ﺳﻄﺮ ﺟﺪﯾﺪ ﻓﻲ اﻟﺠﺪول ﻟﺘﺨﺰﯾﻦ اﻟﺒﯿﺎﻧﺎت ﻓﯿﮫ‬
‫)(‪dRow = rs.Tables("HnHnEmp").NewRow‬‬

‫‪REM : HnHn :‬ﻋﻤﻠﯿﺔ ﻧﻘﻞ اﻟﺒﯿﺎﻧﺎت ﻣﻦ اﻟﺤﻘﻮل إﻟﻰ ﺣﻘﻮل اﻟﺠﺪول‬
‫'أﻣﺎ ﻋﻦ ﻃﺮﯾﻖ ﺗﺤﺪﯾﺪ اﺳﻤﺎء اﻟﺤﻘﻮل اﻟﺘﻲ ﻓﻲ اﻟﺠﺪول إو ﻋﻦ ﻃﺮﯾﻖ اﻟﻔﮭﺮﺳﺔ‬
‫‪REM : HnHn : dRow.Item("LastName") = TextBox2.Text‬‬
‫‪REM : HnHn : OR Index‬‬

‫‪dRow.Item(1) = TextBox2.Text‬‬
‫‪dRow.Item(2) = TextBox3.Text‬‬
‫‪dRow.Item(3) = TextBox4.Text‬‬
‫‪dRow.Item(4) = TextBox5.Text‬‬
‫‪dRow.Item(5) = TextBox6.Text‬‬
‫‪dRow.Item(6) = TextBox7.Text‬‬

‫‪REM HnHn :‬اﺿﺎﻓﺔ اﻟﺴﺠﻞ ﻟﻠﺠﺪول‬

‫)‪rs.Tables("HnHnEmp").Rows.Add(dRow‬‬

‫‪REM HnHn :‬ﻋﻤﻠﯿﺔ اﻟﺘﺤﺪﯾﺚ ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت‬
‫)"‪Dp.Update(rs, "HnHnEmp‬‬
‫"(‪MsgBox‬ﺗﻤﺖ ﻋﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ واﻟﺤﻔﻆ ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت ﺑﻨﺠﺎح)"‬

‫ﺗﺤﺪﯾﺚ ﺑﯿﺎﻧﺎت اﻟﻄﺮﯾﻘﺔ اﻟﺜﺎﻧﯿﺔ ‪: INSERT INTO‬‬
‫وﻓﻲ ھﺬه اﻟﻤﺮﺣﻠﺔ ﺗﺘﻢ ﻋﻤﻠﯿﺔ ﺗﺤﺪﯾﺚ اﻟﺒﯿﺎﻧﺎت ﺑﺎﻟﺨﻄﻮات اﻟﺘﺎﻟﯿﺔ‬

‫ ]‪[1‬ﺗﻌﺮﯾﻒ اﻟﻤﺘﻐﯿﺮ ﻣﻦ ﻧﻮع أﻣﺮ ]‪[OleDbCommand‬‬‫ ]‪[2‬ﺗﺤﺪﯾﺪ ﻣﺴﺎر اﻻﺗﺼﺎل واﺳﻨﺎده ﻟﻠﻤﺘﻐﯿﺮ‬‫ ]‪[3‬ﺗﺤﺪﯾﺪ ﻧﻮع اﻻﻣﺮ وﺳﯿﻜﻮن ﻣﻦ ﻧﻮع ﻧﺺ ‪ ..‬ﻷﻧﻨﺎ ﻧﺤﻦ ﻣﻦ ﺳﯿﻘﻮم ﺑﻜﺘﺎﺑﺔ اﻻﺳﺘﻌﻼم ﯾﺪوﯾﺎ‬‫ ]‪[4‬ﻛﺘﺎﺑﺔ ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم ﻷﺿﺎﻓﺔ اﻟﺤﻘﻮل ﻟﻠﺠﺪول‬‫ ]‪[5‬ﻓﺘﺢ اﻻﺗﺼﺎل ﻷﺗﻤﺎم اﻟﻌﻤﻠﯿﺔ اﻟﻨﮭﺎﺋﯿﺔ‬‫ ]‪[6‬ﺣﺼﺮ اﻟﺴﺠﻼت اﻟﺘﻲ ﺳﺘﺘﺄﺛﺮ ﺑﻌﻤﻠﯿﺔ اﻷﺿﺎﻓﺔ‬‫‪[7] -‬اﻏﻼق اﻻﺗﺼﺎل‬

‫واﻟﺸﻔﺮة ﺳﺘﻜﻮن ﻛﺎﻟﺘﺎﻟﻲ ‪....‬‬
‫ﻛﻮد‬
‫‪REM HnHn :‬ﺗﻌﺮﯾﻒ ﻣﺘﻐﯿﺮ واﺳﻨﺎده إﻟﻰ ﻛﻮﻣﺎﻧﺪ ﻟﯿﻘﻮم ﺑﻌﻤﻠﯿﺔ اﻟﺤﻔﻆ ﻟﺠﻤﻠﺔ اﻻﺿﺎﻓﺔ‬
‫‪Dim SavInto As New OleDb.OleDbCommand‬‬

‫‪REM HnHn :‬ﺗﺤﺪﯾﺪ ﻣﺴﺎر اﻻﺗﺼﺎل ﻟﻠﻤﺘﻐﯿﺮ‬
‫‪SavInto.Connection = Con‬‬

‫‪REM HnHn :‬ﺗﺤﺪﯾﺪ ﻧﻮع اﻷﻣﺮ وﺳﯿﻜﻮن ﻣﻦ ﻧﻮع ﻧﺺ ﻷﻧﻨﺎ ﺳﻨﻘﻮم ﺑﻜﺘﺎﺑﺔ اﻻﺳﺘﻌﻼم ﯾﺪوي‬

SavInto.CommandType = CommandType.Text

‫ﺟﻤﻠﺔ اﻻﺿﺎﻓﺔ ﺑـ‬REM HnHn : INSERT
SavInto.CommandText = "INSERT INTO
HnHnEmp(LastName,FirstName,BirthDate,Address,Mobail,Notes)
values ('" & TextBox2.Text & "','" & TextBox3.Text & "',#"
& TextBox4.Text & "#,'" & TextBox5.Text & "'," &
TextBox6.Text & ",'" & TextBox7.Text & "') "

‫ﻓﺘﺢ اﻻﺗﺼﺎل ﻟﻌﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ‬REM HnHn :
Con.Open()

‫ﻟﺤﺼﺮ ﻋﺪد اﻟﺴﺠﻼت اﻟﺘﻲ ﺗﺄﺛﺮت ﺑﻌﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ‬REM HnHn :
SavInto.ExecuteNonQuery()

‫اﻏﻼق اﻻﺗﺼﺎل‬REM HnHn :
Con.Close()

")‫ﺗﻤﺖ ﻋﻤﻠﯿﺔ اﻻﺿﺎﻓﺔ واﻟﺤﻔﻆ ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﯿﺎﻧﺎت ﺑﻨﺠﺎح‬MsgBox("

*****************
‫ﻟﺨﺪﻣﺎت ﺗﺼﻤﯿﻢ وﺑﺮﻣﺠﺔ اﻟﻤﻮاﻗﻊ‬
programmer4ever@yahoo.com
00201063879624

************************

Sign up to vote on this title
UsefulNot useful