问题描述
我想将列的所有行(ItemName)保存到访问数据库中的(itemname)的单个字段中。现在行在1个字段中保存1行数据。但我想将所有行的数据存储在ItemName上的1个字段中。
这是该列的截图。其行必须存储在一个字段中。
[]
我的尝试:
con.Open();
for(int i = 0; i< ; dataGridView1.Rows.Count - 1; i ++)
{
string amount = dataGridView1.Rows [i] .Cells [0] .Value.ToString();
OleDbCommand cmd = new OleDbCommand(insert into sale(ItemName)values(+ amount +'),con) ;
cmd.ExecuteNonQuery();
MessageBox.Show(Dat a注册);
}
i want to save all rows of column(ItemName) into single field of (itemname) in access database. right now rows are saving in 1 row data in 1 field. but i want to store all row's data in 1 field on ItemName.
here is screenshot of that column. whose rows are need to be store in one field.
https://lh3.googleusercontent.com/-Q-kPiuPwlM4/V2eStcNAC5I/AAAAAAAAAME/XXjEVI_R3Nk7vvFbCX0_c9OxtVVEls13QCCo/s800/Untitled.png[^]
What I have tried:
con.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
string amounts = dataGridView1.Rows[i].Cells[0].Value.ToString();
OleDbCommand cmd = new OleDbCommand("insert into sale (ItemName) values ('" + amounts + "')", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Data Registered");
}
这篇关于如何使用C#中的访问数据库在单个字段中插入多行datagrid列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!