1

I'm getting data from another database the first connection is from con and the second database is DB_Student. I want to get the signature from DB_Student and put it into DB_Attendance which is 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.");
        } 

0 Answers0