如何将 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();
此代码适用于单行,但我需要存储多行,请帮助我。
提前致谢。