简体   繁体   English

如何将多行从GridView Winform Devexpress存储到Access数据库?

[英]How to Store multiple Rows from GridView Winform Devexpress to Access Database?

How to Store Multiple rows from GridView to Access Database. 如何将多行从GridView存储到Access数据库。 I have code to store Single Focused row but i need to Store Multiple Rows ? 我有存储单焦点行的代码,但我需要存储多行? How to Complete My Task ? 如何完成我的任务?

this code I used to store single focused row 我用来存储单个焦点行的代码

 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();

This code work for Single Row but i need to store Multiple Rows, Please Help me. 此代码适用于单行,但我需要存储多行,请帮助我。

Thanks in Advance. 提前致谢。

To obtain all the selected rows, use the GridView GetSelectedRows method. 若要获取所有选定的行,请使用GridView GetSelectedRows方法。 Go through the documentation to know more about this feature. 浏览文档以了解有关此功能的更多信息。

Here is the way that that you can follow. 这是您可以遵循的方式。 You can get the multiple selected rows from the xtragrid as below. 您可以从xtragrid获取多个选定的行,如下所示。

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

Here is an example that let you to do Multiple selection using checkbox (web style) 这是一个示例,可让您使用复选框(网络样式)进行多项选择

References: 参考文献:
How to select rows via an unbound checkbox column 如何通过未绑定的复选框列选择行
How to get multiple selected rows in Grid Control 如何在网格控件中获取多个选定的行
Get values from selected rows from XtraGrid with multiple select and grouping? 从具有多个选择和分组的XtraGrid中从选定的行中获取值?

Edit: By Comment 编辑:通过评论

To traverse through gridview rows you have to see below topic, which clear you everything that you need.. 要遍历gridview行,您必须看到以下主题,该主题清除了您需要的所有内容。
Traversing Rows 横行
Locating Rows 定位行

Example code snippet 示例代码段

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(); }

Reference: 参考:
Iterating over all rows in the grid (not the data source) and retrieving values only for the visible rows 遍历网格中的所有行(非数据源)并仅检索可见行的值
Iterate through Grid rows 遍历网格行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过该过程将多行从gridview存储到数据库 - How to store multiple rows from gridview to database through the procedure 如何在gridview列中写条件? Winform DevExpress - How to write condition in gridview column? Winform DevExpress 从MS Access数据库和Gridview Winforms Devexpress中完全删除吗? - Delete Completely from MS Access Database and Gridview Winforms Devexpress? 如何从Access数据库获取值并在C#winforms Devexpress中的Gridview中进行设置? - How to get the values from Access Database and set in Gridview in C# winforms Devexpress? 如何在Winforms DevExpress中将GridView单元格值保存到Access数据库中? - How to Save GridView Cell Values to Access Database in winforms DevExpress? 如何在Winforms DevExpress中将GridView数据保存到Access数据库? - How to Save GridView Data's to Access Database in Winforms DevExpress? 如何从数据库检索所有行并将其存储在gridview中? - How do I retrieve all rows from a database and store in a gridview? 如何在GridView中访问多行 - How to access multiple rows in a gridview C#Devexpress如何将多个值从WinForm 1传递到WinForm 2? (执行“新建”,“编辑”,“查看”等) - C# Devexpress How to Pass Multiple Value from WinForm 1 to WinForm 2 ? (To perform New,Edit, View and so on) 如何从Winforms Devexpress存储和检索RadioGroup单选按钮和功能区控件的复选框到MS Access数据库? - How to store and retrieve the RadioGroup Radio Button and CheckBox of Ribbon Control from Winforms Devexpress to MS Access Database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM