Three universal code

xiaoxiao2021-03-06  57

public SqlConnection connection_database (string server, string database, string userid, string password) {string str_con; str_con = "server =" server ";" "database =" database ";" "user id =" userid " " "

Password = " password; try {sqlconnection sqlcon = new sqlConnection (STR_CON); sqlcon.open ();

Return Sqlcon;} catch {messagebox.show ("Database connection is not successful! Please fill in database settings correctly", "Error", MessageBoxButtons.ok, MessageBoxicon.Stop; Application.exit (); // Application Exit Return Null ;}} public DataView DvList (string logString, string tablename) // returns view corresponding table {if (sqlconn.State == ConnectionState.Closed) sqlconn.Open ();. SqlDataAdapter myCommand = new SqlDataAdapter (logString, sqlconn); DataSet DS = New DataSet (); try {mycommand.fill (DS, " Tablename ");} catch {messagebox.show ("error");} DataView DV = New DataView (); DV = DS.TABLES [" tablename "] DefaultView;. return Dv;} public void Execute_SQL (string sql, SqlConnection sqlconn) // {// generic SQL functions performed open database Connectivity if (sqlconn.State == ConnectionState.Open) sqlconn.Close (); Sqlconn.open (); sqlcommand cmd = new SQLCOMMAND (SQL, SQLCONN); try {cmd.executenonQuery ();} catch (sqlexception ae) {messagebox.show (ae.Message.Tostring ());} cmd.dispose } Public void show_listview_ data (string select_str, string tablename, ListView lv) // return the tree view generic function {// lv = new ListView (); lv.Clear (); this.sqlDataAdapter1 = new SqlDataAdapter (select_str, this.sqlconn); sqlDataAdapter1 .Fill (Dataset21, " TableName "); // Add column name for (int i = 0; i

} // Add line (database data) for (int J = 0; j

Tostring ());} lv.view = view.details;

}

转载请注明原文地址:https://www.9cbs.com/read-116952.html

New Post(0)