0

GridView から Access データベースに複数の行を格納する方法。単一フォーカス行を格納するコードがありますが、複数の行を格納する必要がありますか? タスクを完了するには?

単一のフォーカスされた行を格納するために使用したこのコード

 OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Srihari/Samples.accdb");
            conn.Open();



            string s1 = (string)gridView1.GetFocusedRowCellValue("Item");
            string s2 = (string)gridView1.GetFocusedRowCellValue("Description");
            string s3 = (string)gridView1.GetFocusedRowCellValue("UoM");
            object quant = gridView1.GetFocusedRowCellValue("Quantity");
            object price = gridView1.GetFocusedRowCellValue("Price");
            object taxp = gridView1.GetFocusedRowCellValue("Tax in Percentage");
            object taxa = gridView1.GetFocusedRowCellValue("Tax in Amount");
            object total = gridView1.GetFocusedRowCellValue("Total");


            int a = Convert.ToInt32(quant);
            int b = Convert.ToInt32(price);
            int c = Convert.ToInt32(taxp);
            int d = Convert.ToInt32(taxa);
            int e = Convert.ToInt32(total);


                OleDbCommand cmd = new OleDbCommand("insert into gridview(Item,Description,UoM,Quantity,Price,TaxinPercentage,TaxinAmount,Total) values ('" + s1 + "','" + s2 + "','" + s3 + "', " + a + " ,  " + b + " , " + c + " , " + d + "  , " + e + " )", conn);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Inserted Successful","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
                Close();

このコードは単一行で機能しますが、複数の行を保存する必要があります。助けてください。

前もって感謝します。

4

1 に答える 1

1

選択したすべての行を取得するには、GridView GetSelectedRowsメソッドを使用します。この機能の詳細については、ドキュメントを参照してください。

これがあなたが従うことができる方法です。以下のように、xtragrid から複数の選択された行を取得できます。

int[] selRows = ((GridView)gridControl1.MainView).GetSelectedRows();
DataRowView selRow = (DataRowView)(((GridView)gridControl1.MainView).GetRow(selRows[0]));
txtName.Text = selRow["name"].ToString();

チェックボックスを使用して複数選択を行う例を次に示します (Web スタイル)。

参照:
バインドされていないチェックボックス列を介して行を選択する
方法 Grid Control で複数の選択された行を取得する方法
複数の選択とグループ化を使用して、XtraGrid から選択された行から値を取得しますか?

編集:コメントで

グリッドビューの行をトラバースするには、以下のトピックを参照する必要があります。これにより、必要なものがすべてクリアされます..行の
トラバース 行の
検索

コード スニペットの例

using DevExpress.XtraGrid.Views.Base;

ColumnView View = gridControl1.MainView as ColumnView;
View.BeginUpdate();
try {
   int rowHandle = 0;
   DevExpress.XtraGrid.Columns.GridColumn col = View.Columns["Category"];
   while(true) {
      // locating the next row 
      rowHandle = View.LocateByValue(rowHandle, col, "SPORTS");
      // exiting the loop if no row is found 
      if (rowHandle == DevExpress.XtraGrid.GridControl.InvalidRowHandle)
         break;
      // perform specific operations on the row found here 
      // ... 
      rowHandle++;
   }
} finally { View.EndUpdate(); }

参照:
(データ ソースではなく) グリッド内のすべての行を反復し、表示されている行のみの値を取得する
グリッド行を反復処理する

于 2013-10-30T14:12:25.563 に答える