【发布时间】:2017-04-26 15:15:16
【问题描述】:
我正在做 winforms.. 我正在比较 datagridview 列值和 db 值..
如果数据库中存在DataGridView 列,如果不存在,我想做更新过程,我想做插入过程。
我试过这段代码
string resultJewelId = null; string QueryJewelId = null;
private void AddStockTable()
{
try
{
Sqlcon = objDB.DBConnection();
QueryJewelId= "Select JewelId from tblStock";
Sqlcmd = new SqlCommand(QueryJewelId, Sqlcon);
dr = Sqlcmd.ExecuteReader();
if (dr.HasRows)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
while (dr.Read())
{
resultJewelId = dr.GetString(0);
if (resultJewelId == dataGridView1[0, i].Value.ToString())
{
MessageBox.Show("Update process");
}
else
{
MessageBox.Show("Insert Process");
}
}
}
}
}
catch (Exception ex)
{ MessageBox.Show(ex.ToString()); }
}
虽然条件工作正常.. 但我不知道如何在 for 循环中移动下一行值..
请支持我。
感谢和问候
【问题讨论】:
标签: c# winforms datagridview