2

ある方法を別の方法よりも使用するメリットを理解する必要があります。状況を単純化するために-私は textbox.text を持っています

データベース テーブルからフィールドを表示する必要があります。テーブルがあるとしましょう: table1 には 1 つの列 col1 があります。

このようなものを指定できます

a) textbox1.text = table1["col1"].Rows[1]

また

b) textbox1.DataBindings.Add() method

誰かがこれらの 2 つの選択肢を比較してくれますか? 他に知っておくべきことはありますか?私は LINQ について知っていますが、それは SQL の代わりに似ていることを理解しています。

私が理解していないもう1つの側面。テーブルのデータを 10 個のテキスト ボックスに入力する場合は、次のようなものを使用できます。

for (int i =0; i<10; i++)
{
Textbox[i].Text = table1["col1"].Rows[i];
}

アプローチ(b)/データバインディングを使用してこれをどのように達成しますか?

助けてくれてありがとう。

4

1 に答える 1

0

Think of Databinding as "dynamic" in that the object you are bound to in the control will change if and when the data changes. so the ideal binding situation is bind it once ( 2 way ) and forget about it.

In your other example the text is set and it will never change unless you explicitly change it and likewise if you need that text data you will have to access the text property and get the value back from the control.

Here is a good example in winforms.

http://www.codeproject.com/Articles/11530/Understanding-Simple-Data-Binding

MS Binding Explained ( note 0 out of 6 vote )

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.databindings.aspx

Another Stack Overflow Simple example

C# Textbox data binding with DataSet

于 2013-09-27T14:43:59.967 に答える