SqlDataAdapter sda = new SqlDataAdapter(); SqlConnection con = new SqlConnection("连接语句"); sda.SelectCommand = new SqlCommand("select max(code) from std1"); //sda.SelectCommand.ExecuteNonQuery(); DataTable dt = new DataTable(); sda.Fill(dt); dgv.DataSource=dt; C#2005编译通过