Я получаю данные из другой базы данных, первое соединение от con, а вторая база данных DB_Student.Я хочу получить подпись от DB_Student и поместить ее в DB_Attendance, который является con.
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.");
}