ÉÏÒ»½Ú£¬ÎÒÃǼòµ¥µÄ½²ÁËÒ»ÏÂÊý¾Ý¿âµÄÓ¦Ó㬶øÎÒÃÇûÓоßÌå˵Ã÷Ö´ÐÐÓï¾äÈçºÎÓÃÓÚÏÔʾ¡£ºÇºÇ£¬ÊÇÁôÔÚÕâÒ»Õ½ÚÖн²µÄ¡£ÕâÀïÎÒÃDZØÐëµÃÁ˽âÒ»ÏÂDataReader,DataSetºÍDataGrid¿Ø¼þ£¬DataGridÊÇÏÔʾ¿Ø¼þ£¬´ó¼Ò×ÔÒÑÈ¥¿´ËüÏà¹ØµÄÓ¦Óã¬ÎÒÃÇÔÚÕâÀï²»¶ß࣬DataReaderºÍDataSet¶¼¿ÉÒÔÓÃÀ´´¢´æÊý¾ÝÄÚÈÝ£¬²»¹ýDataReaderÖ»ÄÜ´¢´æ²éѯµÄ½á¹û£¬DataSet¾ÍÏà¶ÔÀ´Ëµ¸´ÔÓ¶àÁË£¬ËûµÄ¹¦ÄܺÜÇ¿´ó£¬ÎÒÃÇÒ»²½²½À´½²£¬ÕâÒ»½Ú»¹½²²»Í꣬ÎÒÃÇÕâÒ»½ÚÖ»½²Æä¹ØÓÚ´¢´æÊý¾Ý¿âµÄ¹¦ÄÜ£¬ºÇºÇ£¬ÎªÁ˺ÍDataReaderµÄ½²½âÂï. ½²Êý¾Ý¿â£¬Ê×ÏȵÃÓÐÓõÄÊý¾Ý²ÅÐУ¬ÎÒÕâÀïËæ±ã¸ãÁËÒ»¸öÊý¾Ý¿â£¬ÃûΪCompany,ÔÙ¼ÓÁ˼¸ÌõÊý¾Ý½øÈ¥ DataReader DataReader¿´Ãû×Ö¾ÍÖªµÀÁË£¬¾ÍÊǶÁÈ¡Êý¾Ý£¬ÎÒÃÇ¿ÉÒÔͨ¹ýCommandµÄExecute·½·¨£¬½«È¡µÃµÄÊý¾Ý´æÈëDataReader,DataReaderÓкܶ෽·¨ºÍÊôÐÔ£¬³£ÓõÄÊÇRead,ÕâÀïÎÒÒ²²»Ïë¶à½².ÎÒÃÇ»¹ÊÇÏÈ¿´¿´ËüµÄ¾ßÌåÓ¦Óðɡ£ <% @ Page Language="C#" %> <% @ Import Namespace="System.Data" %> <% @ Import Namespace="System.Data.SQL" %> <Script Language="C#" Runat="Server"> public void Page_Load(Object src,EventArgs e) { //¶¨ÒåÓï¾ä string mySelectQuery = "SELECT * from Company"; string myConnString="server=localhost;uid=sa;pwd=123456;database=aspcn"; //Áª½á SQLConnection myConnection = new SQLConnection(myConnString); SQLCommand myCommand = new SQLCommand(mySelectQuery,myConnection); myConnection.Open(); //¶¨ÒåDataReader SQLDataReader myDataReader; //¸³ÓëDataReaderÒÔ½á¹û myCommand.Execute(out myDataReader); //½«DataReaderÓëDataGrid½øÐÐÀ¦°ó show.DataSource=myDataReader; show.DataBind(); //¹Ø±Õ myDataReader.Close(); myConnection.Close(); } </script> <html> <head> <title></title> </head> |