asp.net Êý¾Ý¿â²Ù×÷
ASP.NET²Ù×÷Êý¾Ý¿â
ͨ¹ý¶ÔADO.NETµÄ»ù±¾½²½â£¬ÒÔ¼°½²½âÁËһЩÊý¾ÝÔ´¿Ø¼þµÄ»ù±¾Ó÷¨ºó£¬±¾Õ½«½éÉÜһЩASP.NET²Ù×÷Êý¾Ý¿âµÄ¸ß¼¶Ó÷¨£¬°üÀ¨Ê¹ÓÃSQLHelper£¬ÒÔ¼°Êý¾ÝÔ´¿Ø¼þ¶ÔÊý¾ÝµÄ²Ù×÷¡£±¾ÕÂÊǶÔÇ°ÃæµÄÊý¾Ý¿â֪ʶµÄÒ»ÖÖ²¹³äºÍÌáÉý¡£
9.1 ʹÓÃADO.NET²Ù×÷Êý¾Ý¿â
ÉÏÒ»ÕÂÖнéÉÜÁËADO.NETµÄ»ù±¾¸ÅÄî¡¢ADO.NETµÄ¶ÔÏó£¬ÒÔ¼°ÈçºÎʹÓÃADO.NET¡£Ê¹ÓÃADO.NETÄܹ»¼«´óµÄ·½±ã¿ª·¢ÈËÔ±¶ÔÊý¾Ý¿â½øÐвÙ×÷¶øÎÞÐè¹ØÐÄÊý¾Ý¿âµ×²ãÖ®¼äµÄÔËÐУ¬ADO.NET²»½ö°üÀ¨¶à¸ö¶ÔÏó£¬Í¬Ñù°üÀ¨¶àÖÖ·½·¨£¬ÕâЩ·½·¨¶¼¿ÉÒÔÓÃÀ´Ö´Ðпª·¢ÈËÔ±Ö¸¶¨µÄSQLÓï¾ä£¬µ«ÊÇÕâЩ·½·¨ÊµÏÖ¹ý³ÌÓÖ²»¾¡Ïàͬ£¬±¾½Ú½«½éÉÜADO.NETÖÐÊý¾ÝµÄ²Ù×÷·½·¨¡£
9.1.1 ʹÓÃExecuteReader()²Ù×÷Êý¾Ý¿â
ʹÓÃExecuteReader()²Ù×÷Êý¾Ý¿â£¬ExecuteReader()·½·¨·µ»ØµÄÊÇÒ»¸öSqlDataReader¶ÔÏó»òOleDbDataReader¶ÔÏó¡£µ±Ê¹ÓÃDataReader¶ÔÏóʱ£¬²»»áÏñDataSetÄÇÑùÌṩÎÞÁ¬½ÓµÄÊý¾Ý¿â¸±±¾£¬DataReaderÀà±»Éè¼ÆΪ²úÉúÖ»¶Á¡¢Ö»½øµÄÊý¾ÝÁ÷¡£ÕâЩÊý¾ÝÁ÷¶¼ÊÇ´ÓÊý¾Ý¿â·µ»ØµÄ¡£ËùÒÔ£¬Ã¿´ÎµÄ·ÃÎÊ»ò²Ù×÷Ö»ÓÐÒ»¸ö¼Ç¼±£´æÔÚ·þÎñÆ÷µÄÄÚ´æÖС£
Ïà±ÈÓëDataSet¶øÑÔ£¬DataReader¾ßÓнϿìµÄ·ÃÎÊÄÜÁ¦£¬²¢ÇÒÄܹ»Ê¹ÓýÏÉٵķþÎñÆ÷×ÊÔ´¡£DataReader¶ÔÏóÌṩÁË“Óαê”ÐÎʽµÄ¶ÁÈ¡·½·¨£¬µ±´Ó½á¹ûÖжÁÈ¡ÁËÒ»ÐУ¬Ôò“Óαꔻá¼ÌÐø¶ÁÈ¡µ½ÏÂÒ»ÐС£Í¨¹ýRead·½·¨¿ÉÒÔÅжÏÊý¾ÝÊÇ·ñ»¹ÓÐÏÂÒ»ÐУ¬Èç¹û´æÔÚÊý¾Ý£¬Ôò¼ÌÐøÔËÐв¢·µ»Øtrue£¬·ñÔò·µ»Øfalse¡£Ê¾Àý´úÂëÈçÏÂËùʾ¡£
string str = "server='(local)';database='mytable';uid='sa';pwd='sa'";
SqlConnection con = new SqlConnection(str);
con.Open();
Ïà¹ØÎĵµ£º
ÉÏ´Î×öÁ˸öÏîÄ¿£¬Éæ¼°µ½Êý¾Ý¿âµÄ»¹ÔºÍ»Ö¸´£¬µ½ÍøÉÏÕÒÁËһϣ¬ÊÇÀûÓÃSQLDMOʵÏֵģ¬Ö»ÒªÌí¼ÓSQLDMOÒýÓþͺÃÁË£¬È»ºóÀûÓÃϱߵÄÀàµÄ·½·¨¾Í¿ÉÒÔʵÏÖÁË¡£
ÎÒ°ÑÔ×÷ÕßµÄÀàÀ©³äÁËһϣ¬¿ÉÒÔ×Ô¶¯Ê¶±ðweb.configÀï µÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®£¬¿ÉÒÔͨ¹ý±äÁ¿ÉèÖû¹Ô»Ö¸´µÄÐÅÏ¢¡£
ÐèҪעÒâµÄʱ»¹Ô£¬»¹ÔµÄʱºòÎÊÌ ......
Asp.netÁ¬½ÓSQL Server2000Êý¾Ý¿âÀý³ÌÏê½â:
<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.SqlClient" %>
<script laguage="VB" runat="server">
sub page_load(sender as Object ......
ÏÖÔÚµÄÆóÒµ¼¶¿ª·¢ÏîÄ¿£¬ÌرðÊÇÍøÕ¾Ò»°ã¶¼»áÓõ½log¹¦ÄÜ£¬ÏëÏë´ó²¿·Ö»áÓÃEnterprise Logging Application Block µÄ¹¦ÄÜ »òÕß×Ô¼ºÐ´Ò»¸ö×é¼þ£¬¼Ç¼ϵͳÈÕ־ʼþ£¬¸üºÃµÄ¸ú×ÙÁ˽âϵͳÔËÐÐÇé¿ö, ÏÖÓÃASP.NET MVC µÄ¹ýÂËÊôÐÔʵÏÖlog¹¦ÄÜ£¡
ASP.NET MVCµÄfilter ÊÇÒ»¸öÊôÐÔ£¬¿ÉÒÔÓ¦Ó ......
asp.net(C#)ʵÏÖSQL2000Êý¾Ý¿â±¸·ÝºÍ»¹Ô
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.Htm ......
ÔÚAsp.NetÖÐдÁËÒ»¸ö¸½¼þÉÏ´«ºÍÏÂÔصijÌÐò£¬¸½¼þÉÏ´«µ½Êý¾Ý¿âÖУ¬È»ºó½«¸½¼þµÄGUID±£´æÆðÀ´£¬ÎÒÃÇ¿ÉÒÔ¸ù¾ÝGUIDÀ´ÕÒµ½Êý¾Ý¿âÖеĸ½¼þ£¬Ò»°ã¸½¼þÏÂÔصĴúÂëÊÇ£º
private void Download(string ID)
{
file = logic.GetA ......