ÎÒÃǼÌÐøÇ°ÃæµÄÄÚÈÝ£¬ºÇºÇ£¬Õâ´ÎÖ÷ÒªÊǽ²DataSetµÄÇ¿´ó¹¦ÄÜÀ²£º£©¡£ÉϴδµÁË´ó¼ÒµÄÅÝÅÝ£¨Ëµ»°²»ËãÊýµÄÒâ˼£¬ºþÄÏÈ˶¼ÄÜÌý¶®°É£º£©£©£¬Õâ´ÎÒ»¶¨²»ÄÜÔÙʳÑÔÁË£º£© ÔÚÒ»¸öDataSetÖд¢´æ¶à¸öÊý¾Ý±í ÎÒÃÇÔÚASPÖкܶàÈËÏ°¹ßÓÚʹÓÃRecordSet¶ÔÏóÀ´²Ù×÷Êý¾Ý¿â£¬µ«ÊÇRecordSetÓÐÒ»¸öµÄȱµã¾ÍÊÇÒ»¸öRecordSetÖ»ÄÜ´¢´æÒ»¸öÊý¾Ý±í£¬µ±ÎÒÃÇÐèÒª²Ù×÷¶à¸ö±íʱ£¬²»µÃ²»ÔÚ¶à¸öRecordSetÖÐÀ´»Ø²Ù×÷£¬ËäÈ»ÕâЩÔÚʹÓÃÏ°¹ßºóҲûÓÐʲô£¬µ«ÊǶÔÒ»¸öÐÂÊÖÀ´Ëµ£¬ÕâÒ²ÊÇÒ»¸öºÜÂé·³È˵ÄÊÂÇé¡£¹âÊÇÄÇЩ±äÁ¿Ãû¾Í¿ÉÒÔ¸ã»ëÄ㣬ÏÖÔÚºÃÁË£¬ÔÚASP.NetÖУ¬Ö»ÐèÒªÒ»¸öDataSet¾Í¿ÉÒԸ㶨һÇС£´ó´óµÄ·½±ãÁËÎÒÃǵijÌÐò¡£ÎÒÃÇ»¹ÊÇÀÏÑù×Ó£¬ÏÈ¿´Ò»¶Î³ÌÐò£¬ÔÙÀ´Ï¸Ï¸½²½â¡£ <% @ Page Language="C#" %> <% @ Import Namespace="System.Data" %> <% @ Import Namespace="System.Data.ADO" %> <Script Language="C#" Runat="Server"> public void Page_Load(Object src,EventArgs e) { //Áª½áÓï¾ä string MyConnString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:/test/test.mdb;"; string strComm1 = "select * from UserList"; string strComm2 = "select * from BookList"; //´ò¿ªÒ»¸öÁª½á ADOConnection MyConnection = new ADOConnection(MyConnString); //´ò¿ªÁ½¸öDataSetCommand ADODataSetCommand MyComm1 = new ADODataSetCommand(strComm1,MyConnection); ADODataSetCommand MyComm2 = new ADODataSetCommand(strComm2,MyConnection); DataSet MyDataSet = new DataSet(); //°ÑUserList,BookList±í´æÈëDataSet MyComm1.FillDataSet(MyDataSet,"UserList"); MyComm2.FillDataSet(MyDataSet,"BookList"); DataGrid1.DataSource = MyDataSet.Tables["UserList"].DefaultView; DataGrid2.DataSource = MyDataSet.Tables["BookList"].DefaultView; DataGrid1.DataBind(); DataGrid2.DataBind(); } </script> <html> <head> <title></title> </head> <body> <table> <tr> <td> <ASP:DataGrid id="DataGrid1" runat="server" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" AlternatingItemStyle-BackColor="#eeeeee" /> </td> <td> <ASP:DataGrid id="DataGrid2" runat="server" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" AlternatingItemStyle-BackColor="#eeeeee" /> </td> </tr> </table> </body> </html> ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇ´ò¿ªÁËÒ»¸öÃûΪtest.mdbµÄAccessÊý¾Ý¿â£¬È»ºó°ÑËûÆäÖеÄÁ½¸ö±í"UserList"ºÍ"BookList"ʹÓÃÁ½¸öDataGrid¿Ø¼þÏÔʾ³öÀ´¡£ÏÔʾµÄͼƬÈçÏ£º ͼ9-1 ÎÒÃÇÏÖÔÚÀ´·ÖÎöһϴúÂë: string MyConnString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:/test/test.mdb;"; string strComm1 = "select * from UserList"; string strComm2 = "select * from BookList"; ADOConnection MyConnection = new ADOConnection(MyConnString); ADODataSetCommand MyComm1 = new ADODataSetCommand(strComm1,MyConnection); ADODataSetCommand MyComm2 = new ADODataSetCommand(strComm2,MyConnection); ÕâЩ¶¼Ö»ÊÇÔÚ×÷һЩ׼±¸¹¤×÷£¬´ò¿ªÒ»¸öÁª½á£¬²¢ÇÒ´ò¿ªÁ½¸öDataSetCommandÈ¡µÃÁ½¸ö±íµÄÊý¾Ý¡£ DataSet MyDataSet = new DataSet(); ÕâÊÇÎÒÃdzÌÐòµÄ¹Ø¼üÖ®µØ£¬ÕâÀï´ò¿ªÁËÎÒÃÇÒª²Ù×÷µÄDataSet¶ÔÏó¡£ÏÂÃæÎÒÃǾÍÐèÒª½«Êý¾Ý±íµÄÄÚÈÝÌîÈëDataSetÁË¡£ MyComm1.FillDataSet(MyDataSet,"UserList"); MyComm2.FillDataSet(MyDataSet,"BookList"); ÕâÀïÊÇÎÒÃǽñÌìµÄÖ÷ÒªÄÚÈÝ¡£Ç°ÃæµÄ¼¸ÕÂÔø¾Ëµ¹ý£¬ÔÚÒ»¸öDataSetÖпÉÒÔ°üº¬¶àÖÖÊý¾Ý£¬ÕâÀïÎÒÃÇÊÇÍùÕâ¸öÃûΪMyDataSetµÄDataSetÖдæ·ÅÁËÁ½¸öÊý¾Ý¿â±í£¬ÆäʵֻҪԸÒ⣬ÎÒÃÇ»¹¿ÉÒÔÔÚÀïÃæ²åÈëXMLÊý¾Ý£¬¶øÇÒËûÃÇÊDz»»á³öÏÖ³åÍ»µÄ¡£´ó¼Ò¿ÉÒÔ·ÅÐÄʹÓ㬺Ǻǡ£ ÔÙÏÂÃæµÄ´úÂ룬¾ÍÊÇ°ÑMyDataSetµÄÊý¾Ý´«Ë͸øDataGrid¿Ø¼þÏÔʾ¡£ÕâÀï¾Í²»¶à˵ÁË¡£ ÕâÀïÎÒÃÇÖ»ÊǼòµ¥µÄ˵ÁËÒ»ÏÂDataSetÄÜ´æ·Å¶à¸öÊý¾Ý±íµÄ¹¦ÄÜ£¬´ó¼Ò¿´¿´ºÃÏñûÓÐʲôÌرðµÄ¡£ÕâÀï¿´ÆðÀ´È·ÊµºÃÏñûÓÐʲôÌرðµÄ¹¦ÄÜ£¬µ«ÊÇÈç¹ûÅäÉÏDataSetÖеÄÐ޸ġ¢Ìí¼Ó¡¢É¾³ý¹¦ÄÜ£¬ÎÒÃDzÙ×÷Êý¾Ý¿â¾Í±äµÃºÜ¼òµ¥¡£ÎÒÃÇ¿ÉÒÔÏȽ«Êý¾Ý¿â¶ÁÈëDataSet£¬È»ºóÔÚDataSetÖÐÐÞ¸ÄÊý¾Ý£¬Èç¹û¸ÄµÃ¾õµÃ²»ÂúÒ⣬ÎÒÃÇ»¹¿ÉÒÔʹÓÃRejectChanges·½·¨È«Ãæ»Ö¸´£¬×îºóÒ»²¢½»¸øÈ¥Êý¾Ý¿âÈ¥¸üС£ ÏÂÒ»½Ú£¬ÎÒÃÇÔÙÀ´½²½â£¬ÈçºÎʹÓÃDataSetÀ´Ìí¼Ó£¬Ð޸ģ¬É¾³ýÊý¾Ý¡£ |