0

データベースからリッチテキストボックスにデータをバインドしようとしていますが、ここに私のコードがあります:

        DataTable NameTable = new DataTable("NameTable");
        NameTable.Columns.Add("PropertyNo");
        NameTable.Columns.Add("PropertyName");

        DataSet NameSet = new DataSet();
        NameSet.Tables.Add(NameTable);

        selectQry = new SqlCommand("SELECT PropertyNo, PropertyName FROM Property", conn);
        SqlDataAdapter DataAdpt = new SqlDataAdapter(selectQry);

        DataAdpt.Fill(NameSet, "NameTable");

        Binding NameBinding = new Binding("Text", NameSet, "NameTable.PropertyName");
        NameRtb.DataBindings.Add(NameBinding);

最後の値のみを取得しています。誰でも私を助けることができますか?ありがとう。

4

1 に答える 1

0

個人的には、データ テーブルを DatagridView にバインドするのが好きです。

あなたがする必要があるのは:-

バインディング ソースを使用し、その DataSource を DataTable として設定します。次に、Datagridview のデータソースをバインディング ソースとして設定します。

以下の例:-

//DataGridView DataGridView dgView = new DataGridView();

//DataTable と DataGridView を同期するための BindingSource BindingSource bSource = new BindingSource();

//BindingSource DataSource を設定します bSource.DataSource = dTable;

//DataGridView データソースを設定します dgView.DataSource = bSource;

于 2012-04-12T15:58:10.767 に答える