»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > Web¿ª·¢ > ASP.Net
Ç×ÃܽӴ¥ASP.Net(7)
·¢±íÈÕÆÚ£º2003-06-26 00:00:00×÷Õߣº· ³ö´¦£º  

ÉÏÒ»½Ú£¬ÎÒÃǼòµ¥µÄ½²ÁËÒ»ÏÂÊý¾Ý¿âµÄÓ¦Ó㬶øÎÒÃÇûÓоßÌå˵Ã÷Ö´ÐÐÓï¾äÈçºÎÓÃÓÚÏÔʾ¡£ºÇºÇ£¬ÊÇÁôÔÚÕâÒ»Õ½ÚÖн²µÄ¡£ÕâÀïÎÒÃ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>

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.0018