<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>追風箏的小孩 &#187; ADO.NET</title>
	<atom:link href="http://m955.com/wp/archives/tag/adonet/feed" rel="self" type="application/rss+xml" />
	<link>http://m955.com/wp</link>
	<description></description>
	<lastBuildDate>Thu, 03 Nov 2011 14:47:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>連結資料庫四大步驟（以 ASP.NET 為例）</title>
		<link>http://m955.com/wp/archives/219</link>
		<comments>http://m955.com/wp/archives/219#comments</comments>
		<pubDate>Mon, 22 Jun 2009 13:54:33 +0000</pubDate>
		<dc:creator>blue955</dc:creator>
				<category><![CDATA[程式]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://m955.com/wp/?p=219</guid>
		<description><![CDATA[其實 WinForm 跟 WebForm 在連結資料庫方面其實差不了太多。
PLAIN TEXT
C#:




protected void Page_Load&#40;object sender, EventArgs e&#41;


&#123;


&#160; &#160; //第一：連結SQL資料庫


&#160; &#160; string connstr = @"Data Sou... ]]></description>
			<content:encoded><![CDATA[<p>其實 WinForm 跟 WebForm 在連結資料庫方面其實差不了太多。</p>
<div class="igBar"><span id="lcsharp-2"><a href="#" onclick="javascript:showPlainTxt('csharp-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-2">
<div class="csharp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//第一：連結SQL資料庫</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF0000;">string</span> connstr = <span style="color: #808080;">@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\test_Data.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; SqlConnection conn = <a href="http://www.google.com/search?q=new+msdn.microsoft.com" target="_blank"><span style="color: #008000;">new</span></a> SqlConnection<span style="color: #000000;">&#40;</span>connstr<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; conn.<span style="color: #0000FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//第二：執行SQL指令</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF0000;">string</span> sqlstr = <span style="color: #808080;">"select * from test"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; SqlCommand cmd = <a href="http://www.google.com/search?q=new+msdn.microsoft.com" target="_blank"><span style="color: #008000;">new</span></a> SqlCommand<span style="color: #000000;">&#40;</span>sqlstr,conn<span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; SqlDataReader dr = cmd.<span style="color: #0000FF;">ExecuteReader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//第三：印出資料</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>dr.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"文章編號："</span> + dr<span style="color: #000000;">&#91;</span><span style="color: #808080;">"id"</span><span style="color: #000000;">&#93;</span> + <span style="color: #808080;">"&lt;br&gt;"</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"日　　期："</span> + dr<span style="color: #000000;">&#91;</span><span style="color: #808080;">"test_time"</span><span style="color: #000000;">&#93;</span> + <span style="color: #808080;">"&lt;br&gt;"</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"文章標題："</span> + dr<span style="color: #000000;">&#91;</span><span style="color: #808080;">"title"</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"&lt;hr&gt;"</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//第四：關閉連線</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cmd.<span style="color: #0000FF;">Cancel</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; dr.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; conn.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; conn.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>文章參考於：<a href="http://findbook.tw/book/9789862042380/basic" target="_blank">ASP.NET專題實務-適用C# 作者：周棟祥</a></p>
]]></content:encoded>
			<wfw:commentRss>http://m955.com/wp/archives/219/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>驗證 ASP.NET Web 網頁中的使用者輸入</title>
		<link>http://m955.com/wp/archives/210</link>
		<comments>http://m955.com/wp/archives/210#comments</comments>
		<pubDate>Sun, 21 Jun 2009 16:04:58 +0000</pubDate>
		<dc:creator>blue955</dc:creator>
				<category><![CDATA[程式]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://m955.com/wp/?p=210</guid>
		<description><![CDATA[工具：RequiredFieldValidator
驗證：必要輸入項
說明：確保使用者不會略過輸入項目。如需詳細資訊，請參閱 HOW TO：驗證 ASP.NET 伺服器控制項的必要項目。
工具：CompareValidator
驗證：與某個值的比... ]]></description>
			<content:encoded><![CDATA[<p>工具：<a href="http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx" target="_blank">RequiredFieldValidator</a><br />
驗證：必要輸入項<br />
說明：確保使用者不會略過輸入項目。<a href="http://msdn.microsoft.com/zh-tw/library/e78xxk8k.aspx" target="_blank">如需詳細資訊，請參閱 HOW TO：驗證 ASP.NET 伺服器控制項的必要項目。</a></p>
<p>工具：<a href="http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.comparevalidator.aspx" target="_blank">CompareValidator</a><br />
驗證：與某個值的比較<br />
說明：使用比較運算子 (例如小於、等於、大於)，將使用者輸入的值與常數值、另一個控制項的值，或特定資料型別做比較。<a href="http://msdn.microsoft.com/zh-tw/library/ad548tzy.aspx" target="_blank">如需詳細資訊，請參閱 HOW TO：比對特定值驗證 ASP.NET 伺服器控制項和 HOW TO：比對資料型別驗證 ASP.NET 伺服器控制項。</a></p>
<p>工具：<a href="http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.rangevalidator.aspx" target="_blank">RangeValidator</a><br />
驗證：範圍檢查<br />
說明：檢查使用者的輸入是否介於指定的上下限之間。您可以檢查成對的數字、英文字母字元和日期內的範圍。如需詳細資訊，<a href="http://msdn.microsoft.com/zh-tw/library/bk58fdzx.aspx" target="_blank">請參閱 HOW TO：比對範圍值驗證 ASP.NET 伺服器控制項。</a></p>
<p>工具：<a href="http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.regularexpressionvalidator.aspx" target="_blank">RegularExpressionValidator</a><br />
驗證：樣式比對<br />
說明：檢查輸入是否符合規則運算式 (Regular Expression) 所定義的樣式。這類的驗證可讓您檢查字元 (例如電子郵件地址、電話號碼、郵遞區號等項目中的字元) 的預期順序。<a href="http://msdn.microsoft.com/zh-tw/library/6xh899wy.aspx" target="_blank">如需詳細資訊，請參閱 HOW TO：比對模式驗證 ASP.NET 伺服器控制項。</a></p>
<p>工具：<a href="http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.customvalidator.aspx" target="_blank">CustomValidator</a><br />
驗證：使用者定義<br />
說明：使用您自己撰寫的邏輯驗證使用者的輸入。這類驗證可讓您檢查執行階段時衍生的值。如需詳細資訊，<a href="http://msdn.microsoft.com/zh-tw/library/f5db6z8k.aspx" target="_blank">請參閱 HOW TO：使用 ASP.NET 伺服器控制項的自訂函式驗證</a>和 <a href="http://msdn.microsoft.com/zh-tw/library/s5z00s5e.aspx" target="_blank">HOW TO：比對資料庫值驗證 ASP.NET 伺服器控制項。</a></p>
<p><a href="http://msdn.microsoft.com/zh-tw/library/bwd43d0x.aspx" target="_blank"><br />
MSDN</a></p>
]]></content:encoded>
			<wfw:commentRss>http://m955.com/wp/archives/210/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 中易混淆的數據類型</title>
		<link>http://m955.com/wp/archives/173</link>
		<comments>http://m955.com/wp/archives/173#comments</comments>
		<pubDate>Mon, 08 Dec 2008 15:27:39 +0000</pubDate>
		<dc:creator>blue955</dc:creator>
				<category><![CDATA[程式]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://m955.com/wp/archives/173</guid>
		<description><![CDATA[本文摘自「藍色理想」http://www.blueidea.com/tech/program/2004/1724.asp。
(1)char、varchar、text和nchar、nvarchar、ntext   char 和varchar的長度都在1到8000之間，它們的區別在於char是定長字符數據，而varchar是變長... ]]></description>
			<content:encoded><![CDATA[<p>本文摘自「藍色理想」<a href="http://www.blueidea.com/tech/program/2004/1724.asp。" target="_blank">http://www.blueidea.com/tech/program/2004/1724.asp。</a></p>
<p>(1)char、varchar、text和nchar、nvarchar、ntext   <br />char 和varchar的長度都在1到8000之間，它們的區別在於char是定長字符數據，而varchar是變長字符數據。所謂定長就是長度固定的，當輸入的數據長度沒有達到指定的長度時將自動以英文空格在其後面填充，使長度達到相應的長度；而變長字符數據則不會以空格填充。text存儲可變長度的非 Unicode數據，最大長度為2^31-1(2,147,483,647)個字符。 </p>
<p>後面三種數據類型和前面的相比，從名稱上看只是多了個字母&quot;n&quot;，它表示存儲的是Unicode數據類型的字符。寫過程序的朋友對Unicode應該很瞭解。字符中，英文字符只需要一個字節存儲就足夠了，但漢字眾多，需要兩個字節存儲，英文與漢字同時存在時容易造成混亂，Unicode字符集就是為瞭解決字符集這種不兼容的問題而產生的，它所有的字符都用兩個字節表示，即英文字符也是用兩個字節表示。nchar、nvarchar的長度是在1到4000之間。和char、varchar比較：nchar、nvarchar則最多存儲4000個字符，不論是英文還是漢字；而char、varchar最多能存儲8000個英文，4000個漢字。可以看出使用nchar、nvarchar數據類型時不用擔心輸入的字符是英文還是漢字，較為方便，但在存儲英文時數量上有些損失。 </p>
<p>(2)datetime和smalldatetime   <br />datetime：從1753年1月1日到9999年12月31日的日期和時間數據，精確到百分之三秒。    <br />smalldatetime：從1900年1月1日到2079年6月6日的日期和時間數據，精確到分鍾。 </p>
<p>(3)bitint、int、smallint、tinyint和bit   <br />bigint：從-2^63(-9223372036854775808)到2^63-1(9223372036854775807)的整型數據。    <br />int：從-2^31(-2,147,483,648)到2^31-1(2,147,483,647)的整型數據。    <br />smallint：從-2^15(-32,768)到2^15-1(32,767)的整數數據。    <br />tinyint：從0到255的整數數據。    <br />bit：1或0的整數數據。 </p>
<p>(4)decimal和numeric   <br />這兩種數據類型是等效的。都有兩個參數：p（精度）和s（小數位數）。p指定小數點左邊和右邊可以存儲的十進制數字的最大個數，p必須是從 1到38之間的值。s指定小數點右邊可以存儲的十進制數字的最大個數，s必須是從0到p之間的值，默認小數位數是0。 </p>
<p>(5)float和real   <br />float：從-1.79^308到1.79^308之間的浮點數字數據。    <br />real：從-3.40^38到3.40^38之間的浮點數字數據。在SQL Server中，real的同義詞為float(24)。</p>
]]></content:encoded>
			<wfw:commentRss>http://m955.com/wp/archives/173/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BindingSource 和 BindingNavigator</title>
		<link>http://m955.com/wp/archives/127</link>
		<comments>http://m955.com/wp/archives/127#comments</comments>
		<pubDate>Thu, 22 May 2008 06:16:55 +0000</pubDate>
		<dc:creator>blue955</dc:creator>
				<category><![CDATA[亂講]]></category>
		<category><![CDATA[ADO.NET]]></category>

		<guid isPermaLink="false">http://m955.com/wp/archives/127</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;&#160; BindingSource 類似 DataSet 算是一個資料流的中繼站，和 DataSet 不同的是 BindingSource 提供的功能比較多，支援資料繫結，能夠替表單封裝資料來源，和 BindingNavigator ... ]]></description>
			<content:encoded><![CDATA[<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; BindingSource 類似 DataSet 算是一個資料流的中繼站，和 DataSet 不同的是 BindingSource 提供的功能比較多，支援資料繫結，能夠替表單封裝資料來源，和 BindingNavigator 搭配，可以輕易的做出許多功能。</p>
<p>一如剛剛上面所提，BindingSource 重要的元件特性有以下各點：</p>
<ol>
<li>中間階層的間接取質</li>
<li>將資料來源視為一個清單</li>
<li>能夠在設計階段繫結到商業物件（要用錢買的）</li>
<li>同步化管理（Currency Management）</li>
<li>自訂的項目建立</li>
<li>交易式的項目建立</li>
<li>與 BindingSource 互相搭配</li>
</ol>
<p>基本模型如下：</p>
<p><a href="http://farm4.static.flickr.com/3053/2512591975_10017ba368_o.png" target="_blank" rel="lightbox"><img alt="BindingSource.png" hspace="hspace" src="http://farm4.static.flickr.com/3053/2512591975_6ca23a93dd_m.jpg" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://m955.com/wp/archives/127/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>建立資料庫連接字串的方法</title>
		<link>http://m955.com/wp/archives/123</link>
		<comments>http://m955.com/wp/archives/123#comments</comments>
		<pubDate>Tue, 20 May 2008 15:32:38 +0000</pubDate>
		<dc:creator>blue955</dc:creator>
				<category><![CDATA[程式]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://m955.com/wp/?p=123</guid>
		<description><![CDATA[一、使用 ConnectionStringBuilder
1.連接 Access
PLAIN TEXT
VB.NET:




Dim builder As New OleDbConnectionStringBuilder


builder.Provider = "Microsoft.Jet.OLEDB.4.0"


builder.DataSource = "&#124;DataDirectory&#124;\test.mdb"


builder.Add&#40;"Jet ... ]]></description>
			<content:encoded><![CDATA[<p>一、使用 ConnectionStringBuilder<br />
1.連接 Access</p>
<div class="igBar"><span id="lvbnet-7"><a href="#" onclick="javascript:showPlainTxt('vbnet-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">VB.NET:</span>
<div id="vbnet-7">
<div class="vbnet">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">Dim</span> builder <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> OleDbConnectionStringBuilder</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">builder.<span style="color: #0000FF;">Provider</span> = <span style="color: #808080;">"Microsoft.Jet.OLEDB.4.0"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">builder.<span style="color: #0000FF;">DataSource</span> = <span style="color: #808080;">"|DataDirectory|\test.mdb"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">builder.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"Jet OLEDB:Database Password"</span>, <span style="color: #808080;">"123456"</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">Dim</span> <span style="color: #0600FF;">str</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> = builder.<span style="color: #0000FF;">ConnectionString</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Return <span style="color: #0600FF;">str</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<span id="more-123"></span><br />
2.連接 SQLServer</p>
<div class="igBar"><span id="lvbnet-8"><a href="#" onclick="javascript:showPlainTxt('vbnet-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">VB.NET:</span>
<div id="vbnet-8">
<div class="vbnet">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">Dim</span> builder <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> SqlConnectionStringBuilder</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">builder.<span style="color: #0000FF;">DataSource</span> = <span style="color: #808080;">"(local)\SQLEXPRESS"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">builder.<span style="color: #0000FF;">InitialCatalog</span> = <span style="color: #808080;">"北風貿易"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">builder.<span style="color: #0000FF;">IntegratedSecurity</span> = <span style="color: #0600FF;">True</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">Dim</span> <span style="color: #0600FF;">str</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> = builder.<span style="color: #0000FF;">ConnectionString</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Return <span style="color: #0600FF;">str</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>3.連接 MySql (必須安裝 <a href="http://dev.mysql.com/downloads/connector/" target="_blank">MySql.Data</a> 外掛) 請參考...</p>
<div class="igBar"><span id="lvbnet-9"><a href="#" onclick="javascript:showPlainTxt('vbnet-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">VB.NET:</span>
<div id="vbnet-9">
<div class="vbnet">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">Imports</span> MySql.<span style="color: #0000FF;">Data</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">Imports</span> MySql.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">MySqlClient</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> Form1</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Form1_Load<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, _</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> <span style="color: #FF8000;">MyBase</span>.<span style="color: #0000FF;">Load</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> builder <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> MySqlConnectionStringBuilder</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #0000FF;">Server</span> = <span style="color: #808080;">"localhost"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #0000FF;">UserID</span> = <span style="color: #808080;">"root"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #0000FF;">Password</span> = <span style="color: #808080;">"123456"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #0000FF;">Database</span> = <span style="color: #808080;">"test"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> <span style="color: #0600FF;">str</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> = builder.<span style="color: #0000FF;">ConnectionString</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> conn <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> MySqlConnection<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">str</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> commCMD <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> = <span style="color: #808080;">"select * from product"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> da <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> MySqlDataAdapter<span style="color: #000000;">&#40;</span>commCMD, conn<span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> ds <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> DataSet</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; conn.<span style="color: #0600FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; da.<span style="color: #0000FF;">Fill</span><span style="color: #000000;">&#40;</span>ds, <span style="color: #808080;">"pro"</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; DataGridView1.<span style="color: #0000FF;">DataSource</span> = ds.<span style="color: #0000FF;">Tables</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"pro"</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; conn.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>二、使用自行撰寫連線字串，此方法容易因為人為疏失而產生錯誤<br />
1.連接 SQLServer</p>
<div class="igBar"><span id="lvbnet-10"><a href="#" onclick="javascript:showPlainTxt('vbnet-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">VB.NET:</span>
<div id="vbnet-10">
<div class="vbnet">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">SqlConnection1</span>.<span style="color: #0000FF;">ConnectionString</span> = _</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080;">"Data Source=(local)\SQLEXPRESS; _</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080;">Initial Catalog=北風貿易; _</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080;">Integrated Security=True"</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://m955.com/wp/archives/123/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ADO.NET 資料存取的2種方法</title>
		<link>http://m955.com/wp/archives/105</link>
		<comments>http://m955.com/wp/archives/105#comments</comments>
		<pubDate>Sat, 12 Apr 2008 04:11:12 +0000</pubDate>
		<dc:creator>blue955</dc:creator>
				<category><![CDATA[程式]]></category>
		<category><![CDATA[ADO.NET]]></category>

		<guid isPermaLink="false">http://m955.com/wp/archives/105</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;&#160; 在程式開發中，都無可避免的要接觸到資料庫，無論你對它喜愛與否，它都無所不在，根據一項非官方統計，近年來軟體的開發近 8 成都與資料庫有關，而 ADO.NE... ]]></description>
			<content:encoded><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在程式開發中，都無可避免的要接觸到資料庫，無論你對它喜愛與否，它都無所不在，根據一項非官方統計，近年來軟體的開發近 8 成都與資料庫有關，而 ADO.NET 正是 VB2005 中存取資料庫的一個類別庫，它提供完整方法對資料庫的操作，在 FromWork 2.0 中 ADO.NET 支援的資料庫連接，你可以參考這個網站 <a title="http://www.connectionstrings.com/" href="http://www.connectionstrings.com/" target="_blank">ConnectionStrings</a>，因為很多，所以不一一列出。</p>
<p><span id="more-105"></span></p>
<p>無論你使用哪一種資料庫，在操作方面都離不開基本的 4 個動作：</p>
<ol>
<li>修改</li>
<li>新增</li>
<li>刪除</li>
<li>排序</li>
</ol>
<p>&nbsp;</p>
<p>在 ADO.NET 中提供了兩種操作的方式，供 Programmer 使用：</p>
<ol>
<li><strong><font color="#ff0000">資料集</font></strong></li>
<li><strong><font color="#ff0000">資料命令操作</font></strong></li>
</ol>
<p><font color="#0000ff"></font>&nbsp;</p>
<p><font color="#0000ff">1-1 資料集的存取模式：</font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 資料集簡單的解釋， 就是透過資料配接器 (DataAdapter) 執行資料命令 (SQL陳述式) 以及資料連線，將所傳回的結果集 Result 快取於記憶體當中，然後放進 DataSet 物件的資料表 (Tables) 中，使用者就可以透過 DataSet 物件來存取資料內容。這一種存取方式稱為 中斷式連接。</p>
<p><font color="#0000ff">1-2 使用資料集的優點：</font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其優點為不會一直開啟對資料庫的連線造成連線獨占，使其他使用者無法連線，對資料庫的負擔較小，而在資料存取上的效能也較好。</p>
<ol>
<li>能夠使用多個資料表</li>
<li>能夠處理來自多個異質資料來源的資料</li>
<li>於分散式應用程式的各階層間移動資料</li>
<li>與其他應用程式交換資料</li>
<li>資料繫結</li>
<li>維護資料記錄以便反複使用</li>
<li>程式撰寫容易</li>
</ol>
<p><font color="#0000ff"></font>&nbsp;</p>
<p><font color="#0000ff">2-1 資料命令操作的存取模式：</font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 資料命令操作，就是直接透過 Command 物件執行 SQL陳述式，直接存取資料庫，將所傳回的結果集 Result 放進 DataReader 容器物件以供使用者存取。 </p>
<p><font color="#0000ff">2-1 使用資料命令操作的優點：</font></p>
<ol>
<li>提供自主且額外的功能</li>
<li>更完整的控制權</li>
<li>負荷較低</li>
<li>在某些狀況下可以讓程式碼更精簡 </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://m955.com/wp/archives/105/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

