我从另一个数据库获取数据,第一个连接来自con,第二个数据库是DB_Student。我想从DB_Student获取签名并将其放入具有约束力的DB_Attendance中。
SqlCommand cmd = new SqlCommand();
cmd = con.CreateCommand();
foreach (DataGridViewRow row in dgvAtt.Rows)
{
if (row.Cells.Count >= 4 && row.Cells[4].Value != null)
{
con.Open();
cmd.CommandType = CommandType.Text;
string Query = "INSERT INTO TBL_Attendance(Signature) SELECT
Signature FROM DB_Students.TBL_Student WHERE Name = '" +
row.Cells[4].Value.ToString() + "'";
cmd.CommandText = Query;
cmd.ExecuteNonQuery();
con.Close();
}
else
{
MessageBox.Show("Please Delete the row without name.");
}