ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ74²¿·Ö
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡14¡10¡£¡¡Properties¡¡of¡¡Dataset¡¡Designer¡¡table¡¡structure¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡properties¡¡show¡¡the¡¡exact¡¡syntax¡¡of¡¡the¡¡SQL¡¡INSERT¡¡and¡¡SELECT¡¡mands¡£¡¡Remember¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡these¡¡two¡¡statements¡¡are¡¡used¡¡to¡¡add¡¡and¡¡select¡¡data¡¡from¡¡database¡¡tables¡£¡¡This¡¡illustrates¡¡that¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡Dataset¡¡Designer¡¡code¡¡is¡¡no¡¡different¡¡than¡¡the¡¡ADO¡¡code¡¡£¨except¡¡the¡¡dataset¡¡is¡¡a¡¡cache£©¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡consider¡¡the¡¡following¡¡code£»¡¡generated¡¡by¡¡the¡¡Dataset¡¡Designer£»¡¡to¡¡bind¡¡the¡¡columns¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡the¡¡draws¡¡table¡¡to¡¡the¡¡generated¡¡data¡¡structure¡¡£¨in¡¡¡¡lotteryDataSet¡£Designer¡£vb£©¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡Sub¡¡InitAdapter£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Me¡£_adapter¡¡=¡¡New¡¡Global¡£System¡£Data¡£SqlClient¡£SqlDataAdapter¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡tableMapping¡¡As¡¡Global¡£System¡£Data¡£mon¡£DataTableMapping¡¡=¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡Global¡£System¡£Data¡£mon¡£DataTableMapping¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£SourceTable¡¡=¡¡¡¨Table¡¨¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£DataSetTable¡¡=¡¡¡¨draws¡¨¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨draw_date¡¨£»¡¡¡¨draw_date¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨first_number¡¨£»¡¡¡¨first_number¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨second_number¡¨£»¡¡¡¨second_number¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨third_number¡¨£»¡¡¡¨third_number¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨fourth_number¡¨£»¡¡¡¨fourth_number¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨fifth_number¡¨£»¡¡¡¨fifth_number¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨sixth_number¡¨£»¡¡¡¨sixth_number¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tableMapping¡£ColumnMappings¡£Add£¨¡¨bonus¡¨£»¡¡¡¨bonus¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Me¡£_adapter¡£TableMappings¡£Add£¨tableMapping£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Me¡£_adapter¡£Insertmand¡¡=¡¡New¡¡Global¡£System¡£Data¡£SqlClient¡£Sqlmand¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Me¡£_adapter¡£Insertmand¡£Connection¡¡=¡¡Me¡£Connection¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Me¡£_adapter¡£Insertmand¡£mandText¡¡=¡¡¡¨INSERT¡¡INTO¡¡£§dbo£§¡££§draws£§¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨£§draw_date£§£»¡¡£§first_number£§£»¡¡£§second_number£§£»¡¡£§third_n¡¨&¡¡_¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨umber£§£»¡¡£§fourth_number£§£»¡¡£§fifth_number£§£»¡¡£§sixth_number£§£»¡¡£§bonus£§£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡413¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡HA¡¡P¡¡TE¡¡R¡¡¡¡¡¡1¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡R¡¡E¡¡L¡¡AT¡¡IO¡¡N¡¡A¡¡L¡¡¡¡¡¡D¡¡AT¡¡AB¡¡A¡¡SE¡¡¡¡¡¡D¡¡A¡¡TA¡¡391¡¡
VALUES¡¡£¨@draw_¡¨&¡¡_¡¡¡¡
¡¡¡¡¡¡¡¡¡¨date£»¡¡@first_number£»¡¡@second_number£»¡¡@third_number£»¡¡@fourth_number£»¡¡¡¡¡¡
@fifth_numbe¡¨&¡¡_¡¡¡¡
¡¡¡¡¡¡¡¡¡¨r£»¡¡@sixth_number£»¡¡@bonus£©¡¨¡¡
¡¡¡¡¡¡¡¡Me¡£_adapter¡£Insertmand¡£mandType¡¡=¡¡Global¡£System¡£Data¡£mandType¡£Text¡¡
¡¡¡¡¡¡¡¡Me¡£_adapter¡£Insertmand¡£Parameters¡£Add£¨New¡¡¡¡¡¡
Global¡£System¡£Data¡£SqlClient¡£SqlParameter£¨¡¨@draw_date¡¨£»¡¡¡¡¡¡
Global¡£System¡£Data¡£SqlDbType¡£DateTime£»¡¡0£»¡¡¡¡¡¡
Global¡£System¡£Data¡£ParameterDirection¡£Input£»¡¡0£»¡¡0£»¡¡¡¨draw_date¡¨£»¡¡¡¡¡¡
Global¡£System¡£Data¡£DataRowVersion¡£Current£»¡¡false£»¡¡Nothing£»¡¡¡¨¡¨£»¡¡¡¨¡¨£»¡¡¡¨¡¨£©£©¡¡
¡¡¡¡¡¡¡¡Me¡£_adapter¡£Insertmand¡£Parameters¡£Add£¨New¡¡¡¡¡¡
Global¡£System¡£Data¡£SqlClient¡£SqlParameter£¨¡¨@first_number¡¨£»¡¡¡¡¡¡
Global¡£System¡£Data¡£SqlDbType¡£Int£»¡¡0£»¡¡¡¡
Global¡£System¡£Data¡£ParameterDirection¡£Input£»¡¡0£»¡¡0£»¡¡¡¨first_number¡¨£»¡¡¡¡¡¡
Global¡£System¡£Data¡£DataRowVersion¡£Current£»¡¡false£»¡¡Nothing£»¡¡¡¨¡¨£»¡¡¡¨¡¨£»¡¡¡¨¡¨£©£©¡¡
¡¡¡¡¡¡¡¡¡£¡¡¡¡¡£¡¡¡¡¡£¡¡
End¡¡Sub¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡code¡¡shows¡¡how¡¡close¡¡the¡¡generated¡¡code¡¡is¡¡to¡¡a¡¡variation¡¡of¡¡the¡¡code¡¡used¡¡to¡¡¡¡
insert¡¡data¡¡in¡¡the¡¡ADO¡¡section¡£¡¡The¡¡generated¡¡code¡¡is¡¡more¡¡explicit¡¡and¡¡verbose¡¡than¡¡the¡¡¡¡
previous¡¡code£»¡¡but¡¡that¡¡does¡¡not¡¡matter£»¡¡since¡¡you¡¡are¡¡not¡¡supposed¡¡to¡¡edit¡¡the¡¡generated¡¡code¡£¡¡¡¡
You¡¡are¡¡supposed¡¡to¡¡use¡¡the¡¡Dataset¡¡Designer¡£¡¡
¡öNote¡¡¡¡The¡¡Dataset¡¡Designer¡¡gives¡¡you¡¡the¡¡advantage¡¡of¡¡not¡¡having¡¡to¡¡provide¡¡bindings¡¡between¡¡Visual¡¡¡¡
Basic¡¡and¡¡a¡¡database£»¡¡and¡¡an¡¡easy¡¡binding¡¡between¡¡a¡¡user¡¡interface¡¡and¡¡the¡¡database¡£¡¡By¡¡providing¡¡a¡¡GUI¡¡¡¡
where¡¡you¡¡can¡¡drag£»¡¡drop£»¡¡and¡¡so¡¡on£»¡¡the¡¡Dataset¡¡Designer¡¡just¡¡makes¡¡it¡¡much¡¡simpler¡¡to¡¡write¡¡that¡¡code¡£¡¡
Using¡¡the¡¡Generated¡¡Code¡¡
Using¡¡the¡¡code¡¡generated¡¡by¡¡the¡¡Dataset¡¡Designer¡¡is¡¡easy£»¡¡as¡¡long¡¡as¡¡you¡¡know¡¡what¡¡is¡¡going¡¡on¡£¡¡¡¡
The¡¡Dataset¡¡Designer¡¡generates¡¡two¡¡major¡¡pieces¡¡of¡¡code£º¡¡a¡¡table¡¡adapter¡¡and¡¡a¡¡dataset¡£¡¡The¡¡¡¡
table¡¡adapter¡¡is¡¡code¡¡used¡¡to¡¡interact¡¡with¡¡the¡¡table¡¡directly¡¡and¡¡is¡¡the¡¡link¡¡between¡¡your¡¡code¡¡¡¡
and¡¡the¡¡database¡£¡¡If¡¡you¡¡wanted¡¡to¡¡add£»¡¡select£»¡¡or¡¡delete¡¡items£»¡¡use¡¡the¡¡table¡¡adapter¡£¡¡When¡¡you¡¡¡¡
select¡¡data£»¡¡the¡¡data¡¡will¡¡fill¡¡a¡¡dataset¡£¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡the¡¡code¡¡to¡¡insert¡¡a¡¡record¡¡into¡¡the¡¡draws¡¡table¡¡£¨in¡¡the¡¡DatabaseConsoleEx¡¡¡¡
application£©¡£¡¡
Dim¡¡table¡¡As¡¡DatabaseConsoleEx¡£lotteryDataSetTableAdapters¡£drawsTableAdapter¡¡=¡¡_¡¡
¡¡¡¡New¡¡DatabaseConsoleEx¡£lotteryDataSetTableAdapters¡£drawsTableAdapter£¨£©¡¡
table¡£Insert£¨DateTime¡£Now£»¡¡2£»¡¡12£»¡¡14£»¡¡31£»¡¡18£»¡¡4£»¡¡20£©¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡is¡¡a¡¡trivial¡¡two¡liner¡£¡¡It¡¡instantiates¡¡the¡¡drawsTableAdapter£»¡¡and¡¡then¡¡calls¡¡the¡¡¡¡
Insert£¨£©¡¡method¡¡to¡¡add¡¡a¡¡record¡£¡¡Connecting¡¡to¡¡the¡¡database£»¡¡executing¡¡the¡¡mand£»¡¡and¡¡¡¡
assigning¡¡the¡¡parameters¡¡are¡¡done¡¡automatically¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡414¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
392¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡R¡¡E¡¡L¡¡A¡¡TI¡¡O¡¡N¡¡AL¡¡¡¡¡¡DA¡¡TA¡¡B¡¡AS¡¡E¡¡¡¡¡¡D¡¡AT¡¡A¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡Generated¡¡code¡¡is¡¡both¡¡a¡¡blessing¡¡and¡¡a¡¡curse¡£¡¡Generated¡¡code¡¡hides¡¡plexity¡¡and¡¡makes¡¡it¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡simpler¡¡for¡¡you¡¡to¡¡get¡¡your¡¡job¡¡done¡£¡¡But¡¡as¡¡you¡¡saw¡¡in¡¡the¡¡code¡¡excerpts£»¡¡there¡¡is¡¡quite¡¡a¡¡bit¡¡going¡¡on¡¡behind¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡scenes£»¡¡and¡¡if¡¡you¡¡don¡¯t¡¡understand¡¡ADO£»¡¡you¡¡will¡¡not¡¡know¡¡what¡¡to¡¡do¡¡when¡¡things¡¡go¡¡wrong¡£¡¡For¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡example£»¡¡when¡¡is¡¡a¡¡connection¡¡to¡¡the¡¡database¡¡made£¿¡¡The¡¡only¡¡way¡¡to¡¡know¡¡that¡¡is¡¡to¡¡look¡¡at¡¡the¡¡generated¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡source¡¡code¡¡and¡¡follow¡¡the¡¡ADO¡¡calls¡£¡¡A¡¡connection¡¡to¡¡a¡¡database¡¡is¡¡made¡¡the¡¡first¡¡time¡¡you¡¡call¡¡one¡¡of¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡SQL¡¡methods¡¡£¨for¡¡example£»¡¡¡¡Insert£¨£©£©£»¡¡not¡¡when¡¡the¡¡adapter¡¡is¡¡initialized¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡retrieve¡¡and¡¡iterate¡¡the¡¡data¡¡in¡¡the¡¡table£»¡¡use¡¡the¡¡following¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡dataset¡¡As¡¡DatabaseConsoleEx¡£lotteryDataSet¡¡=¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡DatabaseConsoleEx¡£lotteryDataSet£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡table¡¡As¡¡DatabaseConsoleEx¡£lotteryDataSetTableAdapters¡£drawsTableAdapter¡¡=¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡DatabaseConsoleEx¡£lotteryDataSetTableAdapters¡£drawsTableAdapter£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡count¡¡As¡¡Integer¡¡=¡¡table¡£Fill£¨dataset¡£draws£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Record¡¡count¡¡is¡¡£¨¡¨¡¡&¡¡dataset¡£draws¡£Count¡¡&¡¡¡¨£©£¨¡¨¡¡&¡¡count¡¡&¡¡¡¨£©¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡row¡¡As¡¡DatabaseConsoleEx¡£lotteryDataSet¡£drawsRow¡¡In¡¡dataset¡£draws¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Date¡¡£¨¡¨¡¡£«¡¡row¡£draw_date¡£ToString£¨£©¡¡&¡¡¡¨£©¡¡£¨¡¨¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡&¡¡row¡£first_number¡¡&¡¡¡¨£©¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡variable¡¡table¡¡is¡¡initialized¡¡to¡¡an¡¡adapter¡¡that¡¡connects¡¡to¡¡the¡¡draws¡¡table¡£¡¡The¡¡variable¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dataset¡¡is¡¡an¡¡empty¡¡collection¡¡ready¡¡for¡¡the¡¡draws¡¡table¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡fill¡¡the¡¡data¡¡table¡¡in¡¡the¡¡dataset£»¡¡the¡¡method¡¡table¡£Fill£¨£©¡¡is¡¡called£»¡¡and¡¡the¡¡destination¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡the¡¡dataset¡£draws¡¡data¡¡table¡£¡¡After¡¡having¡¡called¡¡¡¡Fill£¨£©£»¡¡the¡¡number¡¡of¡¡records¡¡read¡¡is¡¡returned¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡assigned¡¡to¡¡count¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡iterate¡¡the¡¡individual¡¡rows£»¡¡a¡¡For¡¡Each¡¡loop¡¡is¡¡used¡£¡¡It¡¡references¡¡the¡¡type¡¡drawsRow£»¡¡and¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡each¡¡instance¡¡of¡¡drawsRow¡¡has¡¡data¡¡members¡¡that¡¡represent¡¡the¡¡draw_date£»¡¡first_number£»¡¡and¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡other¡¡columns¡£¡¡The¡¡iteration¡¡of¡¡the¡¡individual¡¡rows¡¡resembles¡¡the¡¡iteration¡¡of¡¡a¡¡collection¡£¡¡The¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ADO¡¡example¡¡used¡¡a¡¡While¡¡loop¡¡and¡¡required¡¡you¡¡to¡¡know¡¡which¡¡column¡¡was¡¡associated¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡which¡¡SELECT¡¡field¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡the¡¡basics¡¡of¡¡ADO¡¡and¡¡the¡¡Dataset¡¡Designer¡£¡¡Here¡¡are¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡main¡¡points¡¡to¡¡remember£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡real¡¡problem¡¡when¡¡using¡¡a¡¡relational¡¡database¡¡and¡¡a¡¡programming¡¡language¡¡like¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡is¡¡the¡¡mismatch¡¡of¡¡set¡based¡¡operations¡¡and¡¡individual¡¡object¡¡operations¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡To¡¡access¡¡a¡¡relational¡¡database£»¡¡you¡¡can¡¡use¡¡ADO¡£¡¡There¡¡is¡¡an¡¡ADO¡¡database¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡driver¡¡for¡¡each¡¡relational¡¡database¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡Dataset¡¡Designer¡¡code¡¡is¡¡based¡¡on¡¡ADO£»¡¡and¡¡thus¡¡if¡¡you¡¡understand¡¡ADO£»¡¡you¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡be¡¡able¡¡to¡¡understand¡¡how¡¡the¡¡Dataset¡¡Designer¡¡works¡¡and¡¡how¡¡it¡¡can¡¡be¡¡optimized¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡415¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡HA¡¡P¡¡TE¡¡R¡¡¡¡¡¡1¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡R¡¡E¡¡L¡¡AT¡¡IO¡¡N¡¡A¡¡L¡¡¡¡¡¡D¡¡AT¡¡AB¡¡A¡¡SE¡¡¡¡¡¡D¡¡A¡¡TA¡¡393¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡using¡¡ADO£»¡¡the¡¡steps¡¡are¡¡typically¡¡to¡¡connect¡¡to¡¡a¡¡database£»¡¡create¡¡a¡¡mand£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡populate¡¡the¡¡parameters£»¡¡execute¡¡the¡¡mand£»¡¡retrieve¡¡the¡¡data¡¡£¨if¡¡necessary£©£»¡¡close¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡mand£»¡¡and¡¡close¡¡the¡¡connection¡£¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡¡¡SQL¡¡is¡¡a¡¡language¡¡used¡¡to¡¡manipulate¡¡the¡¡tables¡¡of¡¡a¡¡relational¡¡database¡£¡¡You¡¡need¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡learn¡¡SQL¡¡on¡¡top¡¡of¡¡learning¡¡how¡¡to¡¡use¡¡ADO¡£¡¡
Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡
The¡¡following¡¡are¡¡two¡¡exercises¡¡for¡¡applying¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡The¡¡basis¡¡of¡¡the¡¡lottery¡¡application¡¡is¡¡defined¡¡in¡¡terms¡¡of¡¡a¡¡database£»¡¡tables£»¡¡and¡¡data¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Write¡¡a¡¡console¡¡application¡¡that¡¡populates¡¡the¡¡draws¡¡table¡¡using¡¡a¡¡lottery¡¡file¡£¡¡Write¡¡a¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡console¡¡application¡¡that¡¡dumps¡¡the¡¡contents¡¡of¡¡the¡¡draws¡¡table¡¡as¡¡a¡¡lottery¡¡file¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Create¡¡a¡¡console¡¡application¡¡that¡¡accepts¡¡as¡¡mand¡line¡¡arguments¡¡a¡¡winner¡¡and¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡date¡¡of¡¡the¡¡draw¡£¡¡Your¡¡console¡¡application¡¡must¡¡account¡¡for¡¡doubles¡¡and¡¡populate¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡both¡¡the¡¡persons¡¡and¡¡winners¡¡tables¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡416¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡417¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
C¡¡¡¡H¡¡¡¡A¡¡¡¡P¡¡¡¡T¡¡¡¡E¡¡¡¡R¡¡¡¡¡¡¡¡¡¡1¡¡¡¡5¡¡
¡ö¡¡¡ö¡¡¡ö¡¡
Learning¡¡About¡¡LINQ¡¡
In¡¡the¡¡previous¡¡chapter£»¡¡you¡¡learned¡¡about¡¡how¡¡to¡¡access¡¡a¡¡database¡¡using¡¡the¡¡traditional¡¡¡¡
ADO¡¡technologies¡£¡¡When¡¡you¡¡make¡¡ADO¡¡requests£»¡¡you¡¡are¡¡making¡¡SQL¡¡calls¡¡and¡¡¡¡
organizing¡¡the¡¡result¡¡set¡¡data¡¡using¡¡SQL¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Language¡¡Integrated¡¡Query¡¡£¨LINQ£©¡¡is¡¡a¡¡technology¡¡that¡¡lets¡¡you¡¡organize¡¡your¡¡results¡¡in¡¡a¡¡¡¡
consistent¡¡manner£»¡¡regardless¡¡of¡¡the¡¡underlying¡¡source¡¡of¡¡the¡¡data¡£¡¡Why¡¡yet¡¡another¡¡technology¡¡¡¡
to¡¡query¡¡information£¿¡¡The¡¡answer¡¡is¡¡related¡¡to¡¡XML¡£¡¡
¡¡¡¡¡¡¡¡¡¡XML¡¡is¡¡a¡¡technology¡¡used¡¡to¡¡represent¡¡information¡¡in¡¡a¡¡hierarchical¡¡manner¡£¡¡You¡¡saw¡¡an¡¡¡¡
example¡¡of¡¡XML¡¡in¡¡Chapter¡¡12¡£¡¡XML¡¡has¡¡solved¡¡many¡¡problems¡¡in¡¡an¡¡elegant¡¡and¡¡understand
able¡¡manner¡£¡¡One¡¡of¡¡the¡¡solutions¡¡proposed¡¡by¡¡XML¡¡is¡¡the¡¡ability¡¡to¡¡reference¡¡information¡¡in¡¡¡¡
an¡¡XML¡¡structure¡¡with¡¡XPath£»¡¡which¡¡is¡¡a¡¡way¡¡of¡¡referencing¡¡an¡¡object¡¡structure¡¡using¡¡a¡¡set¡¡of¡¡¡¡
filters¡£¡¡Using¡¡XPath£»¡¡you¡¡can¡¡find¡¡any¡¡node£»¡¡and¡¡the¡¡filters¡¡can¡¡include¡¡the¡¡presence¡¡of¡¡depen
dent¡¡elements£»¡¡which¡¡is¡¡not¡¡easily¡¡possible¡¡in¡¡other¡¡technologies¡£¡¡Put¡¡simply£»¡¡XPath¡¡and¡¡XML¡¡¡¡
are¡¡very¡¡powerful¡¡techniques¡¡used¡¡to¡¡find¡¡information¡£¡¡
¡¡¡¡¡¡¡¡¡¡You¡¡can¡¡consider¡¡XML¡¡and¡¡XPath¡¡as¡¡inspiration¡¡for¡¡LINQ¡£¡¡Where¡¡LINQ¡¡and¡¡XML¡¡XPath¡¡¡¡
deviate¡¡is¡¡that¡¡LINQ¡¡can¡¡be¡¡used¡¡to¡¡query¡¡Visual¡¡Basic¡¡collection¡¡objects£»¡¡XML¡¡documents£»¡¡and¡¡¡¡
relational¡¡databases¡£¡¡Think¡¡of¡¡LINQ¡¡as¡¡a¡¡general¡¡mechanism¡¡used¡¡to¡¡search¡¡a¡¡collection¡¡of¡¡¡¡
information¡£¡¡The¡¡focus¡¡of¡¡this¡¡chapter¡¡will¡¡be¡¡to¡¡explain¡¡the¡¡mechanics¡¡of¡¡LINQ£»¡¡and¡¡demon
strate¡¡how¡¡to¡¡write¡¡queries¡¡and¡¡use¡¡the¡¡methods¡¡associated¡¡with¡¡the¡¡LINQ¡¡library¡£¡¡¡¡
Finding¡¡the¡¡Frequency¡¡of¡¡Winning¡¡Numbers¡¡
The¡¡lottery¡¡application¡¡we¡¯ve¡¡been¡¡working¡¡with¡¡in¡¡previous¡¡chapters¡¡collects¡¡information¡¡¡¡
about¡¡lottery¡¡drawings¡¡to¡¡predict¡¡the¡¡next¡¡set¡¡of¡¡winning¡¡lottery¡¡numbers¡£¡¡The¡¡idea¡¡is¡¡to¡¡find¡¡¡¡
patterns¡£¡¡Again£»¡¡the¡¡reality¡¡is¡¡that¡¡lottery¡¡drawings¡¡are¡¡random£»¡¡so¡¡even¡¡if¡¡you¡¡could¡¡identify¡¡¡¡
patterns£»¡¡that¡¡wouldn¡¯t¡¡mean¡¡you¡¡could¡¡predict¡¡winning¡¡numbers¡£¡¡However£»¡¡what¡¡is¡¡interesting¡¡¡¡
about¡¡this¡¡problem¡¡is¡¡that¡¡you¡¡can¡¡use¡¡LINQ¡¡to¡¡slice¡¡and¡¡dice¡¡the¡¡data¡£¡¡LINQ¡¡lets¡¡you¡¡keep¡¡the¡¡¡¡
data¡¡as¡¡objects£»¡¡and¡¡to¡¡perform¡¡SQLand¡¡XPath¡like¡¡operations£»¡¡as¡¡you¡¯ll¡¡see¡¡in¡¡this¡¡chapter¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡In¡¡Chapter¡¡10£»¡¡you¡¡saw¡¡a¡¡streaming¡¡architecture£»¡¡where¡¡a¡¡console¡¡application¡¡read¡¡in¡¡text¡¡¡¡
data¡¡and¡¡spat¡¡out¡¡text¡¡data¡£¡¡You¡¡also¡¡saw¡¡examples¡¡of¡¡text¡to¡binary¡¡and¡¡binary¡to¡text¡¡conver
sions¡£¡¡The¡¡application¡¡in¡¡this¡¡chapter¡¡£¨in¡¡the¡¡FrequencyProcessor¡¡project£©¡¡will¡¡read¡¡in¡¡text£»¡¡process¡¡¡¡
the¡¡data£»¡¡and¡¡then¡¡generate¡¡text¡¡describing¡¡the¡¡frequency¡¡of¡¡lottery¡¡numbers¡£¡¡Thus£»¡¡we¡¡need¡¡to¡¡¡¡
use¡¡the¡¡text¡to¡text¡¡interface£»¡¡which¡¡was¡¡defined¡¡in¡¡Chapter¡¡10¡¡as¡¡follows£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡395¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡418¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
396¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡5¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡L¡¡I¡¡N¡¡Q¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IProcessor¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡Process£¨ByVal¡¡input¡¡As¡¡String£©¡¡As¡¡String¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡input¡¡is¡¡a¡¡text¡¡stream¡¡that¡¡looks¡¡like¡¡this£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006¡£03¡£11¡¡3¡¡7¡¡15¡¡28¡¡30¡¡38¡¡44¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006¡£03¡£15¡¡10¡¡18¡¡30¡¡34¡¡41¡¡43¡¡5¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006¡£03¡£18¡¡3¡¡11¡¡12¡¡16¡¡20¡¡40¡¡9¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006¡£03¡£22¡¡2¡¡3¡¡7¡¡13¡¡42¡¡43¡¡41¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006¡£03¡£25¡¡3¡¡10¡¡36¡¡40¡¡43¡¡44¡¡35¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006¡£03¡£29¡¡3¡¡4¡¡8¡¡16¡¡34¡¡39¡¡45¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡want¡¡to¡¡find¡¡the¡¡frequency¡¡of¡¡the¡¡individual¡¡numbers£»¡¡you¡¡could¡¡parse¡¡each¡¡individual¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡number£»¡¡and¡¡then¡¡increment¡¡the¡¡count¡¡of¡¡the¡¡individual¡¡number¡¡as¡¡an¡¡array£»¡¡like¡¡this£º¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡frequency¡¡As¡¡Integer¡¡=¡¡0¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡splitUpText£¨£©¡¡As¡¡String¡¡=¡¡lineOfText¡£Split£¨New¡¡Char£¨£©¡¡£û¡¨¡¡¡¨c£ý£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡frequency£¨Integer¡£Parse£¨splitUpText£¨0£©£©£©¡¡£«=¡¡1¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡frequency£¨Integer¡£Parse£¨splitUpText£¨1£©£©£©¡¡£«=¡¡1¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡split¡¡line¡¡of¡¡text¡¡contains¡¡the¡¡list¡¡of¡¡numbers£»¡¡separated¡¡by¡¡spaces£»¡¡which¡¡is¡¡then¡¡converted¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡a¡¡series¡¡of¡¡numbers£»¡¡each¡¡of¡¡which¡¡is¡¡used¡¡as¡¡an¡¡index¡¡for¡¡the¡¡frequency¡£¡¡The¡¡solution¡¡is¡¡fast¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡works£»¡¡but¡¡it¡¡has¡¡a¡¡big¡¡problem£º¡¡it¡¡is¡¡not¡¡extendable¡£¡¡The¡¡solution¡¡solves¡¡a¡¡single¡¡problem¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡only¡¡a¡¡single¡¡problem¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡example£»¡¡let¡¯s¡¡say¡¡that¡¡you¡¡want¡¡to¡¡figure¡¡out¡¡other¡¡statistical¡¡information£»¡¡such¡¡as¡¡which¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡numeric¡¡binations¡¡occur¡¡most¡¡often¡£¡¡Using¡¡the¡¡previous¡¡solution£»¡¡that¡¡would¡¡require¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡reparsing¡¡the¡¡text¡¡stream¡¡again¡£¡¡That¡¡is¡¡an¡¡expensive¡¡and¡¡tedious¡¡solution¡£¡¡The¡¡better¡¡solution¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡be¡¡to¡¡convert¡¡the¡¡stream¡¡into¡¡a¡¡series¡¡of¡¡objects¡¡that¡¡could¡¡be¡¡processed¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡However£»¡¡the¡¡problem¡¡at¡¡hand¡¡is¡¡calculating¡¡the¡¡frequency¡¡of¡¡individual¡¡numbers¡£¡¡So¡¡why¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡exert¡¡the¡¡extra¡¡effort¡¡if¡¡the¡¡solution¡¡that¡¡solves¡¡the¡¡single¡¡problem¡¡works£¿¡¡Writing¡¡good¡¡code¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡means¡¡solving¡¡problems¡¡using¡¡a¡¡generic¡¡but¡¡specific¡¡approach¡£¡¡You¡¡want¡¡to¡¡write¡¡specific¡¡code¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡so¡¡that¡¡you¡¡do¡¡not¡¡get¡¡bogged¡¡down¡¡in¡¡thinking¡¡about¡¡details¡¡in¡¡the¡¡future£»¡¡and¡¡you¡¡want¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡write¡¡generic¡¡code¡¡so¡¡that¡¡any¡¡future¡¡requirement¡¡does¡¡not¡¡cause¡¡you¡¡to¡¡pletely¡¡rewrite¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡old¡¡application¡£¡¡Knowing¡¡when¡¡to¡¡write¡¡specific¡¡code¡¡and¡¡when¡¡to¡¡write¡¡generic¡¡code¡¡is¡¡really¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡matter¡¡of¡¡experience¡ªthe¡¡only¡¡way¡¡to¡¡learn¡¡is¡¡to¡¡write¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Extending¡¡the¡¡Lottery¡Prediction¡¡System¡¡
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾Ñé½±Àø£¬ÈÏÕæдԴ´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾Ñé½±ÀøŶ£¡