ASP.NET
ͨ¹ý SqlDataSource ¿Ø¼þ£¬¿ÉÒÔʹÓà Web ·þÎñÆ÷¿Ø¼þ·ÃÎÊλÓÚ¹ØϵÊý¾Ý¿âÖеÄÊý¾Ý¡£ÆäÖпÉÒÔ°üÀ¨ Microsoft SQL Server ºÍ Oracle Êý¾Ý¿âÒÔ¼° OLE DB ºÍ ODBC Êý¾ÝÔ´¡£Äú¿ÉÒÔ½« SqlDataSource ¿Ø¼þÓëÊý¾Ý°ó¶¨¿Ø¼þ£¨Èç GridView¡¢FormView ºÍ DetailsView ¿Ø¼þ£©Ò»ÆðʹÓã¬Óü«ÉÙ´úÂë»òÉõÖÁ²»ÓôúÂëÀ´ÔÚ ASP.NET ÍøÒ³ÉÏÏÔʾºÍ²Ù×÷Êý¾Ý¡£
Ò»¡¢±³¾°
SqlDataSource ¿Ø¼þʹÓà ADO.NET ÀàÓë ADO.NET Ö§³ÖµÄÈκÎÊý¾Ý¿â½øÐн»»¥¡£ÕâÀàÊý¾Ý¿â°üÀ¨ Microsoft SQL Server£¨Ê¹Óà System.Data.SqlClient Ìṩ³ÌÐò£©¡¢System.Data.OleDb¡¢System.Data.Odbc ºÍ Oracle£¨Ê¹Óà System.Data.OracleClient Ìṩ³ÌÐò£©¡£Ê¹Óà SqlDataSource ¿Ø¼þ£¬¿ÉÒÔÔÚ ASP.NET Ò³ÖзÃÎʺͲÙ×÷Êý¾Ý£¬¶øÎÞÐèÖ±½ÓʹÓà ADO.NET Àà¡£Ö»ÐèÌṩÓÃÓÚÁ¬½Óµ½Êý¾Ý¿âµÄÁ¬½Ó×Ö·û´®£¬²¢¶¨ÒåʹÓÃÊý¾ÝµÄ SQL Óï¾ä»ò´æ´¢¹ý³Ì¼´¿É¡£ÔÚÔËÐÐʱ£¬SqlDataSource ¿Ø¼þ»á×Ô¶¯´ò¿ªÊý¾Ý¿âÁ¬½Ó£¬Ö´ÐÐ SQL Óï¾ä»ò´æ´¢¹ý³Ì£¬·µ»ØÑ¡¶¨Êý¾Ý£¨Èç¹ûÓУ©£¬È»ºó¹Ø±ÕÁ¬½Ó¡£
1.1¡¢½« SqlDataSource ¿Ø¼þÁ¬½ÓÖÁÊý¾ÝÔ´
ÅäÖà SqlDataSource ¿Ø¼þʱ£¬½« ProviderName ÊôÐÔÉèÖÃΪÊý¾Ý¿âÀàÐÍ£¨Ä¬ÈÏΪ System.Data.SqlClient£©²¢½« ConnectionString ÊôÐÔÉèÖÃΪÁ¬½Ó×Ö·û´®£¬¸Ã×Ö·û´®°üº¬Á¬½ÓÖÁÊý¾Ý¿âËùÐèµÄÐÅÏ¢¡£Á¬½Ó×Ö·û´®µÄÄÚÈݸù¾ÝÊý¾ÝÔ´¿Ø¼þ·ÃÎʵÄÊý¾Ý¿âÀàÐ͵IJ»Í¬¶øÓÐËù²»Í¬¡£ÀýÈ磬SqlDataSource ¿Ø¼þÐèÒª·þÎñÆ÷Ãû¡¢Êý¾Ý¿â£¨Ä¿Â¼£©Ãû£¬»¹ÐèÒªÈçºÎÔÚÁ¬½ÓÖÁ SQL Server ʱ¶ÔÓû§½øÐÐÉí·ÝÑéÖ¤µÄÏà¹ØÐÅÏ¢¡£
Èç¹û²»ÔÚÉè¼Æʱ½«Á¬½Ó×Ö·û´®ÉèÖÃΪ SqlDataSource ¿Ø¼þÖеÄÊôÐÔÉèÖã¬Ôò¿ÉÒÔʹÓà connectionStrings ÅäÖÃÔªËؽ«ÕâЩ×Ö·û´®¼¯ÖÐ×÷ΪӦÓóÌÐòÅäÖÃÉèÖõÄÒ»²¿·Ö½øÐд洢¡£ÕâÑù£¬¾Í¿ÉÒÔ¶ÀÁ¢ÓÚ ASP.NET ´úÂëÀ´¹ÜÀíÁ¬½Ó×Ö·û´®£¬°üÀ¨Ê¹Óà Protected Configuration ¶ÔÕâЩ×Ö·û´®½øÐмÓÃÜ¡£ÏÂÃæµÄʾÀýÑÝʾÈçºÎʹÓô洢ÔÚÃûΪ MyNorthwind µÄ connectionStrings ÅäÖÃÔªËØÖеÄÁ¬½Ó×Ö·û´®Á¬½Óµ½ SQL Server Northwind ʾÀýÊý¾Ý¿â¡£
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>ASP.NET Example</title>
<
Ïà¹ØÎĵµ£º
ÔÚWeb±à³Ì¹ý³ÌÖУ¬´æÔÚןܶలȫÒþ»¼¡£±ÈÈçÔÚÒÔÇ°µÄASP°æ±¾ÖУ¬CookieΪ·ÃÎÊÕߺͱà³ÌÕ߶¼ÌṩÁË·½±ã£¬²¢Ã»ÓÐÌṩ¼ÓÃܵŦÄÜ¡£´ò¿ªIEä¯ÀÀÆ÷£¬Ñ¡Ôñ“¹¤¾ß”²Ëµ¥ÀïµÄ“InternetÑ¡Ï¬È»ºóÔÚµ¯³öµÄ¶Ô»°¿òÀïµ¥»÷“ÉèÖÔ°´Å¥£¬Ñ¡Ôñ“²é¿´Îļþ”°´Å¥£¬ÔÚµ¯³öµÄ´°¿ÚÖУ¬¾Í»áÏÔʾӲÅÌÀï ......
<html>
<head>
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<title>***WSOFT.NET***</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print Õâ¸öÊôÐÔ¿ÉÒÔÔÚ´òӡʱÓÐЧ-->
<mce:st ......
ASP.NET URLË«Ïò¸ÄдµÄʵÏÖ
¡¡¡¡ÎÒÃÇÔÚ½øÐÐWeb³ÌÐò¿ª·¢Ê±£¬ÎªÁ˽øÐÐËÑË÷ÒýÇæÓÅ»¯£¨SEO£©£¬ÍùÍùÐèÒª¶ÔwebµÄ·ÃÎʵØÖ·½øÐÐÓÅ»¯£¬È罫http://localhost/Default.aspx?tab=performanceÐÞ¸ÄΪhttp://localhost/Default_performance.aspx£¬ºóÒ»¸öµØÖ·Äܹ»¸üºÃµØ±»ËÑË÷ÒýÇæËÑË÷µ½£¬´Ó¶ø´ïµ½ÁËËÑË÷ÒýÇæÓÅ»¯µÄÄ¿µÄ¡£Î¢ÈíÓÐÒ»¸ö¿ªÔ´À ......
1.Á¬½ÓÊý¾Ý¿âÎļþ
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|TimeTracker.mdf;User Instance=true" />
SqlConnectionStringBuilderʵÀý»¯Ê±£¬ÒªÓõ½connectionString£¬È磺SqlConnectionStringBuild builder = new SqlC ......