<?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>mr.mu設計工作室 &#187; .Net Framework</title>
	<atom:link href="http://www.mrmu.com.tw/category/otherprogramming/dotnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mrmu.com.tw</link>
	<description>網站設計,珠寶,飾品美學,金工,設計,生活</description>
	<lastBuildDate>Sun, 16 May 2010 01:03:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>BindingSource物件</title>
		<link>http://www.mrmu.com.tw/2008/08/15/bindingsource%e7%89%a9%e4%bb%b6/</link>
		<comments>http://www.mrmu.com.tw/2008/08/15/bindingsource%e7%89%a9%e4%bb%b6/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 03:19:00 +0000</pubDate>
		<dc:creator>mrmu</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[.net framework]]></category>

		<guid isPermaLink="false">http://www.mrmu.com.tw/2008/08/15/bindingsource%e7%89%a9%e4%bb%b6/</guid>
		<description><![CDATA[BindingSource 元件有兩個用途。第一，它會在表單上的控制項繫結至資料時，提供間接取值 (Indirection) 層。這項作業的完成，是透過將 BindingSource 元件繫結至資料來源，然後將表單上的控制項繫結至 BindingSource 元件。所有與資料的進一步互動 (包括巡覽、排序、篩選和更新) 都會透過呼叫 BindingSource 元件來完成。
  
雖然 BindingNavigator 控制項是特別設計用來與 BindingSource 元件搭配使用的，不過還是可以使用 BindingSource 元件將任何 Windows Form 控制項繫結至資料來源，如ComboBox跟DataGridView，繫結至某資料表的BindingSource後，其內容就會是該資料表的記錄。DataGridView元件的欄位(Cell)，也可以表示為控制項(如ComboBoxCell, TextBoxCell等)，這些控制項也可以使用DataSource成員來做Binding。
根據預設，BindingNavigator 控制項所提供的按鈕是對應到 BindingSource 元件上的巡覽方法。
跟TableAdapter一樣，透過精靈操作時，若我們直接將資料表拉入表單(Form)，它會自動加入元件至表單，並做好Binding動作(每個資料表都會有一個BindingSource物件)，不管是使用「詳細資料」或「DataGridView」的方式皆會產生BindingSource物件。 
BindingSource的類別成員 (msdn)     
  

	相關文章
	
	並行違規
	The DELETE statement conflicted with the REFERENCE constraint
	TableAdapter


]]></description>
		<wfw:commentRss>http://www.mrmu.com.tw/2008/08/15/bindingsource%e7%89%a9%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TableAdapter</title>
		<link>http://www.mrmu.com.tw/2008/08/01/tableadapter/</link>
		<comments>http://www.mrmu.com.tw/2008/08/01/tableadapter/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 12:36:00 +0000</pubDate>
		<dc:creator>mrmu</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[.net framework]]></category>

		<guid isPermaLink="false">http://www.mrmu.com.tw/2008/08/01/tableadapter/</guid>
		<description><![CDATA[TableAdapter 提供應用程式與資料庫之間的通訊。TableAdapter 會連接到資料庫、執行查詢或預存程序，然後傳回一個已填入傳回之資料的新資料表，或是將傳回之資料填入現有的 DataTable (DataSet裝著一堆DataTable)。TableAdapter 也可用來將應用程式中更新的資料傳回到資料庫。 
 
透過精靈的操作，vb.net會自動做一些事，大概是這樣的：
1. 新增資料來源 &#8594; 自動建立DataSet，它含有部份原始DB其中一部份的資料表(看你選了哪些資料表進來)&#160;
2.&#160;當我們將資料表拉入表單(Form)時 &#8594; 不管是用「詳細資料」的方式還是DataGridView，vb.net都會自動為該資料表做一個TableAdapter (一般會在Form_Load先幫你作Fill的預設動作，把全部資料查詢出來)，除了生出TableAdapter，還會建立對應控制項的BindingSource物件。
  

	相關文章
	
	並行違規
	The DELETE statement conflicted with the REFERENCE constraint
	BindingSource物件


]]></description>
		<wfw:commentRss>http://www.mrmu.com.tw/2008/08/01/tableadapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>並行違規</title>
		<link>http://www.mrmu.com.tw/2008/07/13/%e4%b8%a6%e8%a1%8c%e9%81%95%e8%a6%8f/</link>
		<comments>http://www.mrmu.com.tw/2008/07/13/%e4%b8%a6%e8%a1%8c%e9%81%95%e8%a6%8f/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 12:10:00 +0000</pubDate>
		<dc:creator>mrmu</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[.net framework]]></category>

		<guid isPermaLink="false">http://www.mrmu.com.tw/2008/07/13/%e4%b8%a6%e8%a1%8c%e9%81%95%e8%a6%8f/</guid>
		<description><![CDATA[接續上篇的練習，在新增一筆記錄後按&#8221;更新&#8221;按鈕，記錄的確會被寫回資料庫，但隨即刪除這筆記錄後再按&#8221;更新&#8221;，另一個錯誤就可能出現了：對於初次見到這個訊息的我而言，我只能感覺到設計這行字的工程師真是天才，試問誰能一眼就了解這是錯在哪呢&#8230;
並行違規的問題似乎是因為第一個存取記錄的人把資料取回應用程式後，在要寫回資料庫時，由於第二個人已改變記錄了，因此造成二個以上的人同時編輯記錄，結果產生並行違規。在這個範例中，第二個人就是你自己。
簡單的解決方式是針對此情況對使用者發出提示，可以使用DBConcurrencyException來得知並行違規的問題發生了(處理並行存取錯誤的說明)，確定要寫入就再做一次Fill及AcceptChanges()，不過最適當的方式還是要視專案情況(不同的商業邏輯)來解決：Private Sub BtnUpdate_Click(ByVal sender As System.Object,_                            ByVal e As System.EventArgs)_                   [...]]]></description>
		<wfw:commentRss>http://www.mrmu.com.tw/2008/07/13/%e4%b8%a6%e8%a1%8c%e9%81%95%e8%a6%8f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The DELETE statement conflicted with the REFERENCE constraint</title>
		<link>http://www.mrmu.com.tw/2008/07/12/the-delete-statement-conflicted-with-the-reference-constraint/</link>
		<comments>http://www.mrmu.com.tw/2008/07/12/the-delete-statement-conflicted-with-the-reference-constraint/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 06:11:00 +0000</pubDate>
		<dc:creator>mrmu</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[.net framework]]></category>

		<guid isPermaLink="false">http://www.mrmu.com.tw/2008/07/12/the-delete-statement-conflicted-with-the-reference-constraint/</guid>
		<description><![CDATA[這是在練習VB.net更新DataSet時遇到的第一個錯誤訊息。
練習更新DataSet時，做出了一個如下圖這樣的表單(一個label, 一個comboBox, 一個button, 兩個DataGridView)：


以NORTHWIND範例資料庫為例，新增Products, Suppliers, Order Details資料表作為資料來源(如右圖)。
Products資料表階層下之所以還有個Order Details的資料表，主要是因為兩者之間有關聯(以ProductsID作關聯)，Products為父資料表，Order Details為子資料表。同樣的，Suppliers與Products之間也有如此關聯(以SupplierID作關聯)。三個資料表之間的關聯如下圖。 

這個簡單的例子要讓User能直接對DataGridView進行新增、刪除、修改後，在表單上提供一個&#8221;更新&#8221;按鈕讓User完成修改後可以將記錄寫回至資料庫。在放好Label, comboBox (DataSource屬性設為Suppliers資料表, DislayMember為Company Name，ValueMember為SupplierID)後，接著直接將資料來源視窗內的Suppliers資料表階層下的Products資料表拉進表單，成為表單中間的DataGridView；同樣的，Products下面的Order Details拉進，為下面的DataGridView。
更新按鈕的Click事件函數如下(為求簡單，先不考慮異常例外的處理)：

Private Sub BtnUpdate_Click(ByVal sender As System.Object,_
           ByVal e As System.EventArgs) Handles BtnUpdate.Click
    Dim dsChanged As DataSet
    dsChanged = NORTHWNDDataSet.GetChanges(DataRowState.Added +_
      [...]]]></description>
		<wfw:commentRss>http://www.mrmu.com.tw/2008/07/12/the-delete-statement-conflicted-with-the-reference-constraint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
