The operation of the database is actually very simple.
DataTable DT = New CustomDataTable ("MyTable1");
DataRow Dr = DT.GetNewRow (TRUE); DR [0] = "Sadfas";
DT.UPDATA (); gridbind ();
Operate with this lightly
/// /// customize the DataTable, encapsulation operation of the database, only the select statement processing /// summary> public class CustomDataTable: DataTable {private SQLServer sqlServer; SqlDataAdapter sqlDataAdapter; // private CustomDataTable () { } private void Init (string SQLString) {sqlServer = SQLServer.Instance (); sqlDataAdapter = new SqlDataAdapter (SQLString, sqlServer.Connection); SqlCommandBuilder custCB = new SqlCommandBuilder (sqlDataAdapter); sqlServer.Connection.Open (); try {sqlDataAdapter. Fillschema (this, Schematype.Source); SqlDataAdapter.Fill (this);} finally {sqlser.connection.close ();}}
/// /// Constructor /// summary> /// SELECT statement or table name param> public customDataTable (string sqlstring) {string SQL = SQLSTRING. Trim (). TouPper (); if (SQL.StartSwith ("SELECT")) {init (SQL);} else {init ("Select * from" SQL); this.tablename = TableName;}}
/// /// Constructor /// summary> /// Table name param> /// condition param > Public CustomDataTable (String Tablename, String Condition) {String SQL = "SELECT * FROM" TABLENAME; if (Condition! = Null && Condition! = "&& condition.trim ()! =" "SQL =" Where " Condition; init (sql); this.tablename = Tablename;
/// /// Submit /// summary> public void UpData () {try {sqlServer.Connection.Open (); sqlServer.BeginTransaction (); sqlDataAdapter.SelectCommand.Transaction = sqlServer.SqlTran; sqlDataAdapter .Update (this); sqlserver.committransaction ();} catch {sqlserver.rollbacktransaction (); throw;} finally {sqlserver.connection.close ();}} /// /// / summary> /// flag, True means new row to the table, FALSE ANTVEE param> /// New Row returns> public DataRow GetNewRow (Bool Flagadd) {DATAROW DR = this.NewRow (); if (flagadd) this.rows.add (dr); Return DR;} /// // / Add new row /// summary > /// New row param> public void address {this.rows.add (dr);}
/// /// Get a row /// summary> /// index param> /// line reference returns> Public DataRow GetRow (int index) {return this.rows [index];
/// /// Get routine /// ///// condition param> /// row set returns> public dataroW [ ] GetRows (String Condition) {Return this.Select (Condition, Null, DataViewRowState.currentrows);
/// /// Delete one line /// summary> /// param> public void deleterow (int index) {this.rows [index] .delete }
/// /// Delete row set /// ////// condition param> public void deleterows (string condition) {Foreach (DataRow Dr in GetRows Dr.Delete ();} /// /// Remove all records in the table ////////mmary> public void delete () {Foreach (DataRow Dr in this.select (null, null, DataViewRowState.currentrows)) Dr.Delete ();} /// /// Settings primary key /// summary> /// key param> public void setPrimaryKey Params string [] keys) {datacolumn [] DC = new datacolumn [keys.Length]; for (int i = 0; i
}