foreach (ListViewItem item in listView1.Items)
{
item.Selected = true;
}
if (cn.State == ConnectionState.Closed) cn.Open();
cm = new SqlCommand();
cm.Connection = cn;
ListViewItem lvi1 = listView1.SelectedItems[0];
string tableName = lvi1.SubItems[2].Text;
string itemcode1 = lvi1.SubItems[0].Text;
string itemcode2 = lvi1.SubItems[1].Text;
string sql = "UPDATE " + tableName + " SET [itemcount]= " + itemcode2 + " WHERE [itemcode]= " + itemcode1 + " AND [itemcount] IS NOT NULL";
cm.CommandText = sql;
cm.ExecuteNonQuery();