C# 它说这是;DB_Student.TBLStudent“;是无效的对象。为什么呢?

C# 它说这是;DB_Student.TBLStudent“;是无效的对象。为什么呢?,c#,sql,C#,Sql,我从另一个数据库获取数据,第一个连接来自con,第二个数据库是DB_Student。我想从DB_学生处获得签名,并将其放入DB_考勤表中,即con SqlCommand cmd = new SqlCommand(); cmd = con.CreateCommand(); foreach (DataGridViewRow row in dgvAtt.Rows) { if (row.Cells.Count >= 4 && row.Ce

我从另一个数据库获取数据,第一个连接来自con,第二个数据库是DB_Student。我想从DB_学生处获得签名,并将其放入DB_考勤表中,即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.");
        } 

我认为您也需要指定架构名称。DB_Student或DB_Students?可能重复
SqlCommand cmd=new SqlCommand();cmd=con.CreateCommand()可以简化为
var cmd=con.CreateCommand()
我认为您也需要指定架构名称。DB_Student或DB_Student?可能重复
SqlCommand cmd=new SqlCommand();cmd=con.CreateCommand()可以简化为
var cmd=con.CreateCommand()