【发布时间】:2014-05-24 14:05:39
【问题描述】:
我用 excel 数据填充网格并想比较数据库中是否存在值?
for (int i = 0; i < dataGridView1.RowCount; i++)
{
if (radioButton1.Checked == true)
{
string strConn = @"Data Source='" + dbconfig.tb1 + "';Initial Catalog='" + dbconfig.tb2 + "';user='" + dbconfig.tb3 + "';pwd='" + dbconfig.tb4 + "'";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT CODE FROM LG_" + dbconfig.tb5 + "_TABLE WHERE CODE NOT LIKE '" + dataGridView1.Rows[i].Cells[0].Value + "'", conn);
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
MessageBox.Show("Check ITEMS" + reader[i].ToString());
}
conn.Close();
}
}
【问题讨论】:
-
你能详细说明你的问题吗
标签: datagridview compare sqldatareader