Recently connected to the database, it summarizes the // This is the insert statement SqlConnection conn = new SqlConnection ("server = MRGAO-PC \ SQLEXPRESS; database = jiaohua; uid = sa; pwd = *********** "); // you can change the connection keyword to your own try {conn. open (); // Open the database string ins = "insert into tb_jiaohua (dtem, dhumidity, dt_humidity) values ('" + tem + "', '" + humidity + "', '"+ t_humidity +"') "; // Insert the data keyword SqlCommand cmd = new SqlCommand (ins, conn); cmd. executeNonQuery (); // execute insert conn. close ();// Close database} catch (Exception ex) {Console. WriteLine ("unable to connect to database! "); Console. writeLine (ex. message);} // The method used to connect to the database is the same, but the insert and query statements may be different, because the insert operation table, but the Query Needs to be displayed. // I think the insert, modify, and delete methods may be the same, but the statement is changed and not verified. Try it by yourself. // This method is intuitive, but you need to connect to the database every time you execute the statement (that is, the first two or three sentences cannot be left blank ). // I used the database connection today and tried it. This method is okay and I have verified it. // The following is the query statement, also verified, the correct SqlConnection conn = new SqlConnection ("server = MRGAO-PC \ SQLEXPRESS; database = jiaohua; uid = sa; pwd = ************ "); try {conn. open (); Console. writeLine ("successfully connected to the database! "); SqlCommand cmd1 = new SqlCommand (" select dtem from tb_jiaohua ", conn); SqlDataReader dr = bytes 1.executereader (); while (dr. read () {Console. write (dr [0]); // the program in the console is not in the form, but in the same principle, dr [0] is equivalent to the first data variable found, it can be displayed in the form control.} Dr. Close (); conn. Close ();} catch (Exception ex) {Console. WriteLine ("cannot connect to the database! "); Console. WriteLine (ex. Message );}