Original link:
http://www.cnblogs.com/beio/archive/2013/01/23/2871958.html
. 1 the SqlConnection con = new new the SqlConnection (); // define objects sqlconnecyion 2 con.ConnectionString = " Server Database .; = = **; UID = SA; pwd =; " ; // specified con connection string property . 3 the try . 4 { . 5 con.Open (); . 6 Response.Write ( " success " ); . 7 con.Close (); . 8 } . 9 the catch 10 { . 11 Response.Write ( " failure " ); 12 is con.Close (); 13 is }
Connect to the database
. 1 the SqlConnection CON = new new the SqlConnection (); 2 con.ConnectionString = " Server Database .; = = airline reservation system; UID = SA; pwd =; " ; . 3 the SqlCommand COM = new new the SqlCommand (); . 4 com.Connection = CON ; . 5 com.CommandText = " Update table set flight aircraft type = 'Boeing 787' where aircraft type = '2' " ; . 6 the try . 7 { . 8 con.Open (); . 9 the try 10 { . 11 com.ExecuteNonQuery (); / /Calling the ExecuteNonQuery () method of data updating is completed 12 / * ** test execution affected rows 13 * larger than the display only if the affected successfully modified row 0 14 * 0 line data without modification under the influence 15 * or performed modification failed error display 16 ** * / . 17 IF (com.ExecuteNonQuery ()> 0 ) 18 is { . 19 Response.Write ( " modified successfully " ); 20 is } 21 is the else 22 is { 23 is Response.Write ( " no modified data "); 24 25 } 26 is } 27 the catch (Exception) 28 { 29 Response.Write ( " modification failure " ); 30 } 31 is con.Close (); 32 } 33 is the catch (Exception) 34 is { 35 Response.Write ( " Database open failed " ); 36 con.Close (); 37 [ }
Updating data using a connector used to perform updata, insert, delete and other statements on time will result in data changes
Reproduced in: https: //www.cnblogs.com/beio/archive/2013/01/23/2871958.html