asp.net³ÌÐòExcelת³ÉXMLµµ
ͨ¹ýAsp.net(C#)Ó¦ÓóÌÐò¶ÁÈ¡±¾µØÉÏ´«µÄExcleÎļþ,´æ·Åµ½DataSetÖÐ,ͨ¹ýDataSetÖеķ½·¨Ö±½ÓÉú³ÉXMLÎļþ.
C# Code
if (this.FileUpload1.PostedFile != null)
{
string filename = this.FileUpload1.FileName.ToString();
string path = @Server.MapPath("../File/") + filename;
this.FileUpload1.PostedFile.SaveAs(path);
//¶ÁÈ¡Óû§ÉÏ´«µÄExcleÎļþ
string conn="Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source ='"+path+"';Extended Properties=Excel 8.0";
OleDbConnection olecon = new OleDbConnection(conn);
olecon.Open();
//×¢Òâ±íÃû,´ò¿ªExcelÎļþºó,×îµ×²¿·ÖÒ³µÄExcleÃû×Ö,
//ĬÈÏÊÇ$Sheet1,$Sheet2,$Sheet3
string sql = "select * from [$Sheet1]";
OleDbDataAdapter oleda = new OleDbDataAdapter(sql,conn);
oleda.Fill(ds);
olecon.Close();
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
string file_name = "20091126002.xml";
&nb
Ïà¹ØÎĵµ£º
ÔÚGlobal.asaxÆô¶¯Ò»ÌõÏ߳̾ÍokÁË£¬ÏÂÃæÊÇÆô¶¯Ï̶߳¨Ê±Ð´ÎļþµÄÀý×Ó
¡¡¡¡Global.asax
¡¡¡¡C# code
¡¡¡¡Code
¡¡¡¡1<%@ Application Language="C#" %>
¡¡¡¡2<%@ Import Namespace="System.IO" %>
¡¡¡¡3<%@ Import Namespace="System.Threading" %>
¡¡¡¡4<script runat="server">
¡¡¡¡5 ......
ASP.NET Ò³ÔËÐÐʱ£¬´ËÒ³½«¾ÀúÒ»¸öÉúÃüÖÜÆÚ£¬ÔÚÉúÃüÖÜÆÚÖн«Ö´ÐÐһϵÁд¦Àí²½Öè¡£ÕâЩ²½Öè°üÀ¨³õʼ»¯¡¢ÊµÀý»¯¿Ø¼þ¡¢»¹ÔºÍά»¤×´Ì¬¡¢ÔËÐÐʼþ´¦Àí³ÌÐò´úÂëÒÔ¼°½øÐгÊÏÖ¡£Á˽âÒ³µÄÉúÃüÖÜÆÚ·Ç³£ÖØÒª£¬ÕâÑù¾ÍÄÜÔÚºÏÊʵÄÉúÃüÖÜÆÚ½×¶Î±àд´úÂ룬ÒÔ´ïµ½Ô¤ÆÚЧ¹û¡£´ËÍ⣬Èç¹û¿ª·¢×Ô¶¨Òå¿Ø¼þ£¬Ôò±ØÐëÊìϤҳÉúÃüÖÜÆÚ£¬´Ó¶øÕýÈ·µØ³õʼ ......
ͨ¹ý SqlDataSource ¿Ø¼þ£¬¿ÉÒÔʹÓà Web ·þÎñÆ÷¿Ø¼þ·ÃÎÊλÓÚ¹ØÏµÊý¾Ý¿âÖеÄÊý¾Ý¡£ÆäÖпÉÒÔ°üÀ¨ Microsoft SQL Server ºÍ Oracle Êý¾Ý¿âÒÔ¼° OLE DB ºÍ ODBC Êý¾ÝÔ´¡£Äú¿ÉÒÔ½« SqlDataSource ¿Ø¼þÓëÊý¾Ý°ó¶¨¿Ø¼þ£¨Èç GridView¡¢FormView ºÍ DetailsView ¿Ø¼þ£©Ò»ÆðʹÓã¬Óü«ÉÙ´úÂë»òÉõÖÁ² ......
1¡¢ÔÚÒ³Ãæ¶¯Ì¬Ìí¼ÓÒ»¸ö¿Ø¼þµÄ·½·¨¡£ ÔÚÒ³ÃæµÄ HTML ´úÂëÉÏÉèÖÃÒ»¸ö asp:PlaceHolder վλ¿Ø¼þ£¬µ±Ò³Ãæ±»¼ÓÔØµÄʱºò£¬ÔÚÕâ¸ö PlaceHolder ¿Ø¼þÉÏÌí¼ÓËùÐèÒªµÄÆäËû¿Ø¼þ¡£
<asp:PlaceHolder runat="server" id="PutLabelHere" /> Sub Page_Load(sender as Object, e ......
ObjectDataSource ¿Ø¼þ»ùÓÚ SelectMethod¡¢InsertMethod¡¢UpdateMethod »ò DeleteMethod ÊôÐÔÖÐËù±êʶµÄ·½·¨Ãû³ÆÒÔ¼°×é³ÉÒµÎñ¶ÔÏó·½·¨Ç©ÃûµÄ²ÎÊýÃûÀ´µ÷ÓÃÒµÎñ¶ÔÏó·½·¨¡£ÔÚÒµÎñ¶ÔÏóÖд´½¨·½·¨Ê±£¬±ØÐëÈ·±£ÒµÎñ¶ÔÏó·½·¨Ëù½ÓÊܵIJÎÊýÃûºÍÀàÐÍÓë ObjectDataSource ¿Ø¼þ´«µÝµÄ²ÎÊýÃûºÍÀàÐÍÆ¥Åä¡££¨²ÎÊý˳Ðò²¢²»ÖØÒª¡££©
  ......