I. This is a C # Connection WinForm Note: (1) You must reference the namespace referenced in this class (2) class in the name of the namespace; use system.data; use system.data.data; using system.data.sqlclient; (3) call Example: dataset ds = new dataset (); string sql = "select * from [user]"; ds = DODATABASE.GETDATASET (SQL); DataGrid1.datasource = DS.TABLES [0] .defaultView; // More than four behaviors The USER table in the 02wangluo database is binding DataSet to DataSet to DataGrid1 // This is called GetDataSet method -> SELECT STRING SQL = "INTO TEST (Test_xingming) VALUES (" TXTUSERID .Text ")"; DODATABASE.EXECUTESQL (SQL); // The two lines are called the ExecuteSQL method in the DODatabase database operation class to perform an increase in the database, delete, change, etc., generally written to Button_Click (3) specific Operation class code: public class doDatabase {public class dodatabase () {// // Todo: Add constructor logic //} public static dataset getDataSet (SQLCONNECTION CONN = new sqlConnection (); DataSet DS = New DataSet (); try {
Conn = new SqlConnection ("Server = localhost; uid = sa; pwd =; dataBase = 02wangluo"); SqlDataAdapter SDA = New SqlDataAdapter (SQL, CONN); SDA.FILL (DS); Return DS;} catch (Exception EX) {Throw (ex);} finally {conn.close ();}} public static int executeSQL (SQLCONNECTION CONN = new sqlConnection (); try {conn = new sqlConnection ("Server = localhost; uid = sa; PWD =; Database = 02wangluo "); SQLCommand Sqlcmd = New SQLCOMMAND (SQL, Conn); conn.open (); returnon sqlcmd.executenononury ();} catch (} catch (eX) {throw ex;} finally {conn.close );}}} 2 ASP.NET C # operation SQL Server 2000 database operation class (1) Class Namespace: use system; use system.data; use system.data.sqlclient; use system.collections; using system. Configuration; (2) Add database connection string in Web.config