DotNet code automatic generation machine implementation

xiaoxiao2021-03-06  40

DOTNET Code Automatic Generator Implementation When we write programs, especially database applications, often encounter such situations: For a given table, write this table corresponding to the class (saying with a fashionable voice It is a business entity class), and the data member of the class is all the fields, and the class contains the addition modification deletion such as the table. Also, for a given stored procedure, you must complete access data or other database operations based on stored procedures.

The following code is that we usually have to complete: 1. Table of the business entity Private IID; public int id {get {return IID;} set {IID = value;} private string name {Get {Return Strname ;} set {strName = value;}} private string strCode; public string Code {get {return strCode;} set {strCode = value;}} private string strDescription; public string Description {get {return strDescription;} set {strDescription = value;}} private int iFatherid; public int Fatherid {get {return iFatherid;} set {iFatherid = value;}} private int iType; public int Type {get {return iType;} set {iType = value;}} private int iUserid; public int usrid {get {iSerid = value;}} ublic bool add ()}} ublic bool add () {sqlconnection conn = sqlconn.instance (). Connecti On; String strsql = "Insert Into Book (ID, Name, Code, Description, FatherId, Type, Userid" "Values ​​(@ID, @name, @code, @description, @fatherid, @Type, @UserID) "; Sqlcommand command = new sqlcommand (strsql, conn); command.parameters.add (" @ id ", sqldbtype.int); command.parameters [" @ id "]. Value = iid; command.parameters.add (" @Name ", sqldbtype.nvarchar, 50); if (strname! = Null) Command.Parameters [" @ name "]. Value = strname; else command.Parameters [" @ name "]. Value = dbnull.value; Command .Parameters.add ("@ code"

Sqldbtype.nvarchar, 255); if (strcode! = Null) Command.Parameters ["@ code"]. Value = strcode; else command.parameters ["@ code"]. Value = dbnull.value; command.Parameters. Add ( "@ Description", SqlDbType.NVarChar, 255);. if (! strDescription = null) command.Parameters [ "@ Description"] value = strDescription; else command.Parameters [ "@ Description"] value = DBNull.. Value; Command.Parameters.Add ("@ FatherID", SqldbType.It); Command.Parameters ["@ FatherID"]. Value = ifatherid; Command.Parameters.Add ("@ type", sqldbtype.int); Command. Parameters ["@ type"]. Value = itype; command.Parameters.add ("@ userid", sqldbtype.int); command.parameters ["@ userid"]. Value = iuserid; try {conn.open (); Command.executenonQuery (); return true;} catch ("error in the database" E.MESSAGE));} finally {conn.close ();}} public bool modify () {SqlConnection conn = SQLCONN.INSTANCE (). Connection; STR ion strsql = "Update book set id = @ID, name = @Name, code = @code, description = @description, fatherid = @fatherid, type = @Type, userid = @Userid" "where id = @ id" Sqlcommand command = new sqlcommand (strsql, conn); command.parameters.add ("@ id", sqldbtype.int); command.parameters ["@ id"]. Value = iid; command.parameters.add ("@ Name ", Sqldbtype.nvarchar, 50); Command.Parameters [" @ name "]. Value =

Strname; Command.Parameters.add ("@ code", sqldbtype.nvarchar, 255); command.parameters ["@ code"]. value = strcode; command.parameters.add ("@ description", sqldbtype.nvarchar, 255 Command.Parameters ["@ description"]. Value = strdescription; command.parameters.add ("@ FatherID", sqldbtype.int); Command.Parameters ["@ FatherID"]. Value = ifatherid; Command.Parameters. Add ("@ type", sqldbtype.int); Command.Parameters ["@ type"]. Value = itype; command.Parameters.Add ("@ userid", sqldbtype.int); command.parameters ["@ userid" ] .Value = iuserid; try {conn.open (); command.executenonquery (); return true;} catch (exception e) {throw ("Error In The Database" E.MESSAGE);} finally {conn.Close ();}} look at the stored procedure: public bool ExeSP_ddms_Modify_Trx (int aiPrsn_trx_no, int aiUlt_incid_no, int aiPrsn_trx_status_cd, DateTime adtTrx_cmpl_dt, string astrEmail_addr) {SqlConnection conn = SqlConn.Instance () C. onnection; string strSPName = "ddms_Modify_Trx"; SqlCommand command = new SqlCommand (strSPName, conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add ( "@ prsn_trx_no", SqlDbType.SmallInt); command.Parameters [ "@ prsn_trx_no ".] value = aiPrsn_trx_no; command.Parameters.Add (" @ ult_incid_no ", SqlDbType.Int); command.Parameters [" @ ult_incid_no "] value = aiUlt_incid_no;. command.Parameters.Add (" @ prsn_trx_status_cd ", SqlDbType .Int);

. Command.Parameters [ "@ prsn_trx_status_cd"] value = aiPrsn_trx_status_cd; command.Parameters.Add ( "@ trx_cmpl_dt", SqlDbType.DateTime); if (adtTrx_cmpl_dt = DateTime.Minvalue!) Command.Parameters [ "@ trx_cmpl_dt"] value. = adtTrx_cmpl_dt;. else command.Parameters [ "@ trx_cmpl_dt"] value = DBNull.value; command.Parameters.Add ( "@ email_addr", SqlDbType.VarChar, 70); if (! astrEmail_addr = null) command.Parameters [ " @email_addr ".] value = astrEmail_addr; else command.Parameters [" @ email_addr "] value = DBNull.value;. try {conn.Open (); command.ExecuteNonQuery (); return true;} catch (Exception e) { "NEW EXCEPTION (" ERROR in the Database " E.MESSAGE));} finally {conn.close ();}} The code for the table above is quite long, but that is just 7 fields, if a table contains In the twenty or thirty fields, I am afraid the code is longer, and the same, check if your write code has an error is also a painful process. However, there is no difficulty of writing these code itself, and many work are repeated, which can't do not inspire us to complete these cumbersome errors. If let's design a program to complete the code above, what should we do? To complete the above work, we should first find the table or stored procedure we have to handle.

We can also be achieved by programming: 1. List all the database server public static ArrayList GetServerList () {ArrayList alServers = new ArrayList (); SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass (); try {SQLDMO.NameList serverList = sqlApp .Listavailablesqlservers (); for (int i = 1; i <= serverList.count; i ) {alservers.add (serverList.Item (i));}}} catch (exception e) {throw (New Exception " Server list error: " E.MESSAGE));} finally {sqlapp.quit ();} Return Alservers;} This, all database server labyrinth condensed, we can use a drop-down list to list all The server allows users to choose one of his needs. 2. Get all database lists of selected servers To complete this job, we need users to enter the username and password of this database server, the code is as follows: public static arraylist getdblist (string strusername, string strusername, string strupwd {arraylist aldbs = new arraylist () ; SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass (); SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass (); try {svr.Connect (strServerName, strUserName, strPwd); foreach (SQLDMO.Database db in svr.Databases) { IF (db.name! = null) Aldbs.Add (DB.NAME);}} Catch (Exception E) {throw ("connection database error:" E.MESSAGE));} finally {svr.disconnect (); Sqlapp.quit ();} Return AldBs;} This will get a list of databases, you can also allow users to choose a database. 3.

Lists all user tables and stored procedures in the selected database, we don't have to use SQLDMO, we need to implement the records in the Sysobjects table of the selected database, of course, the completion of this job requires the following information: The database server name you choose , user name, password, database name and other information: public static ArrayList getTableList (string strServerName, string strDBName, string strUserName, string strPwd) {string strConStr = "data source =" strServerName "; initial catalog =" strDBName " ; password = " strPwd "; persist security info = True; user id = " strUserName; SqlConnection conn = new SqlConnection (strConStr); ArrayList alTbs = new ArrayList (); string strSql =" select * from sysobjects where (xtype = 'u' or xtype = 'p') and category <> 2 ORDER BY Name "; SQLCommand Comm = New SqlCommand (strsql, conn); SqlDataReader sr = null; try {conn.open (); sr = comm.executeReader ); While (sr.read ()) {string strname = sr ["name"]. TOSTRING (); BOOL BLTABLE = SR ["xtype"]. TOSTRING (). Trim (). Toupper () == "u "True: false; tableinfo tb = new TableInfo (strname, bltable); altbs.add (tb);}} catch (exception err) {throw (New Exception) ("Take the list error:" Err.Message));} finally {if (sr! = Null) {sr.close (); sr = null;} conn.close ();} Return Altbs;} Just get all the user tables and stored procedures, pay attention to this sentence: select * from sysobjects where (xtype = 'u' or xtype = 'p') and category <> 2 Order by name, this is a key SQL statement, where Xtype = 'u' represents the user table, Xtype = 'P' indicates that the stored procedure is stored, and Category <> 2 means that it is not a system stored procedure.

The next step is to get all the parameters of all fields or stored procedures in the selected table. We get what we want from the table syscolumns: startAblename = tbinfo.name; string strsql = "select * from syscolumns where id = (" "SELECT ID from sysobjects where name = '" strtablename ") "; sqldataadapter sa = new sqldataadapter (strsql, conn); DataSet DS = new dataset (); sa.fill (DS); so let's put a table ( Or all field information of the stored procedure is placed in the result set DS.

There is a field xtype in syscolumns, which represents the data type of the column, defines two functions, depending on the value of Xtype, the data type and SQLDB data type in the corresponding DOTNET: private string gettype (int itype) {String Strresult = ""; SWITCH {CASE 34: Strresult = "Byte []"; Break; Case 35: Case 99: Case 167: Case 175: Case 231: Case 239: Strresult = "String"; Break; Case 48: CASE 52: Case 56: Case 127: Strresult = "INT"; Break; Case 58: Case 61: Strresult = "DATETIME"; Break; Case 59: Strresult = "Single"; Break; Case 60: Case 106: Case 108: Case 122: Strresult = "decimal"; break; case 62: strresult = "double"; break; case 104: strresult = "bool"; break; default: strRRRESULT = "none"; // "unknow"; break;} return strResult "";} private string getSqlDBType (int iType) {string strResult = ""; switch (iType) {case 34: strResult = "SqlDbType.Image"; break; case 35: strResult = "SqlDbType. TEXT "; Break; Case 48: Strresult =" SQL DbType.TinyInt "; break; case 52: strResult =" SqlDbType.SmallInt "; break; case 56: strResult =" SqlDbType.Int "; break; case 58: strResult =" SqlDbType.SmallDateTime "; break; case 59: strResult = "Sqldbtype.real"; break; case 60: strresult = "sqldbtype.money"; break; case 61: strresult = "sqldbtype.datetime"; Break; case 62: strResult = "sqldbtype.float"; Break;

case 99: strResult = "SqlDbType.NText"; break; case 104: strResult = "SqlDbType.Bit"; break; case 106: strResult = "SqlDbType.Decimal"; break; case 108: strResult = "SqlDbType.Decimal"; break; case 122: strResult = "SqlDbType.SmallMoney"; break; case 127: strResult = "SqlDbType.BigInt"; break; case 165: strResult = "SqlDbType.VarBinary"; break; case 167: strResult = "SqlDbType.VarChar "; break; case 173: strResult =" SqlDbType.Binary "; break; case 175: strResult =" SqlDbType.Char "; break; case 189: strResult =" SqlDbType.Timestamp "; break; case 231: strResult =" SqlDbType .Nvarchar "; Break; Case 239: Strresult =" sqldbtype.nchar "; break; default: strresult =" none "; //" unknow "; break;} return strresult " ";} Of course, there is also a function Introduction, there is a specific usage of it: private string gettypeshort (int itype) {string strresult = ""; switch (gettype (iTYPE) .trim ()) {copy "byte []": Strresult = "img"; case "string": strresult = "str"; break; case "int": strresult = "i"; break; case "datetime": strRRESULT = "dt"; break; case "single" : Strresult = "SIG"; Break; Case "decimal": strresult = "dec"; break; case "double": strresult = "db"; break; case "bool": strResult = "BL"; BREAK;

Default: strresult = "unknow"; Break;} Return Strresult;} Now has the above introduction and function foundation, we can gradually implement our goals: 1. Generate data members of the data entity class Let's take a look, for a field ID, shaping, we define this: private int id {get {return iid;} set {IID = value;}} where IID indicates the data type field name, where the first letter of the field name, code Implemented the following: Private string buildmember (DataSet DS) {StringBuilder SB = New StringBuilder (); Foreach (DATAROW DR IN DS.TABLES [0] .ROWS) {Int itype = (byte) DR ["xipe"]; string strading = getType (iType); string strName = dr [ "name"] ToString ();. strName = UpFirstChar (strName); string strShortType = getTypeShort (iType); string strPrivateline = "private" strType strShortType strName "; / R / N "; sb.append (strprware); string strpublicLine =" public " strtype strname " / r / n "; sb.append (strpublicLine); sb.append (" {/ r / n "); SB.Append ("/ tget / r / n"); sb.append ("/ t {/ r / n"); sb.append ("/ t / treturn" strshorttype strname "; / r / n" ); Sb.append ("/ t} / r / n"); sb.append ("/ tset / r / n"); sb.append ("/ t {/ r / n"); sb.append ("/ t / t" strshorttype strname "= value; / r / n "); sb.append (" / t} / r / n "); sb.append ("} / r / n "); sb.append (" / r / n "); sb.append (" / R / N ");} return sb.tostring ();} DS in the parameter Dataset DS is obtained by the Sa.Fill (DS) of the previous page, DR [" ""] represents a field name, DR ["xType "] Is a field type.

The Upfirstchar function is responsible for putting the first letter of the string: private string Upfirstchar (String Strvalue) {Return Strvalue.substring (0,1) .toupper () Strvalue.Substring (1, strvalue.length - 1);} Data members of the data entity are generated. 2. Generating an Add method ADD method is a bit difficult, you can refer to the program of the first page, and we are through the method of parameters to implement add. One thing to note is that the parameter value is empty when assigning parameters.

The code is implemented as follows: Private String BuildDFunction (DataSet DS) {StringBuilder SB = New StringBuilder (); Sb.Append ("Public Bool Add () / R / N"); sb.append ("{/ r / n"); SB.Append ("/ tsqlconnection conn = SQLCONN.INSTANCE (). Connection; / r / n"); sb.append ("/ r / n"); string strinsert = "/" Insert INTO " STRTABLENAME " ( "; String strparamlist ="; string strparamlist = "; foreach (DataRow Dr in Ds.Tables [0] .ROWS) {String Strname = Dr [" Name "]. Tostring (); strfiledlist = strfiledlist strname " , "; StrParamlist = strparamlist " @ " strname ", ";} strfiledlist = strfiledlist.trim (); strparamlist = strparamlist.trim (). Trimend (','); SB. Append ("/ tstring strsql =" strinsert strfiledlist ") /" / r / n "); sb.append (" / t / ") /"; / r / n "); SB .Append ("/ r / n"); sb.append ("/ tsqlcommand command = new sqlcommand (strsql, conn); / r / n"); Sb.Append ("/ r / n"); foreach (DataRow Dr in ds.tables [0] .ROWS) {string strname = dr [ "name"] ToString ();. string strSqlType = getSqlDBType ((byte) dr [ "xtype"]); string strShortType = getTypeShort ((byte) dr [ "xtype"]); string strvalueName = strShortType UpFirstChar ( Strname); INT Ilen = (int16) DR ["prec"]; string strlen = ""; if (strshorttype == "str") strlen = strlen "," Ilen; string strandsmandname =

"/TCommand.Parameters.add (/"@" strname "/", " strsqltype string "); / r / n "; string strcommandvalue =" /TCommand.Parameters[/"@ " strname " /"].value = " strignename "; / ring strcommandnullvalue = "/TCommand.Parameters[/"@" strname "/"].value = dbnull.value; / r / n" Sb.append (strcommandname); if (strshorttype == "dt") sb.append ("/ tif (" stritalueename "! = DATETIME.MINVALUE) / R / N"); Else IF (strshorttype == " Str ") sb.append (" / TIF (" StrvalueEname "! = null) / r / n "); Else IF (strshorttype ==" img ") sb.append (" / tif (" strValueename " ! = NULL) / R / N "); else sb.append (" "); sb.append (strcommandvalue); if (strshorttype ==" dt "|| strshorttype ==" str "|| strshorttype ==" IMG ") {Sb.append (" / telse / r / n "); sb.append (strcommandnullvalue);} sb.append (" / r / n ");} sb.append (addcatchstring ()); sb.append ("} / r / n"); return sb.toString ();} 3.

EDIT, DELETE implementation method Similar to add, the EDIT method code is as follows: Private string buildmodifyfunction (Dataset DS) {StringBuilder SB = new stringbuilder (); sb.append ("public bool modify () / r / n "); sb.append (" {/ r / n "); sb.append (" / tsqlconnection conn = SQLCONN.INSTANCE (). Connection; / r / n "); string strModify =" string strsql = / " Update " Strtables " STRING STRPARAMLIST = ""; Foreach (DATAROW DR IN DS.TABLES [0]. ROWS) {string strname = DR ["name"]. Tostring (); strparamlist = strparamlist strname "= @" strname ",";} strparamlist = strparamlist.trim (). Trimend (','); sb.append ("/ t" strmodify strparamlist "/" / r / n "); Sb.append ("/ t /" where id = @ ID / "; / r / n"); sb.append ("/ tsqlcommand command = new sqlcommand (strsql, conn); / r / n"); foreach DataRow Dr in Ds.Tables [0]. ROWS) {String Strname = Dr ["Name"]. TOSTRING (); string strsqltype = getsqldbtype ((byte) DR ["xtype"]); string string string strshorttype = gettypeshst (Byte " ) DR ["Xtype"]); String strvalueName = strShortType UpFirstChar (strName); int iLen = (Int16) dr [ "prec"]; string strLen = ""; if (strShortType == "str") strLen = strLen "," iLen; string strCommandName = "/TCommand.Parameters.add (/"@" strname "/", " strsqltype strlish "); / r / n "; string strcommandvalue ="

/TCommand.Parameters[/"@ " strname " /"].value = " StrValuename "; / r / n "; sb.append (strcommandvalue); sb.append (" / r / n ");} sb.append (addcatchString ()); sb.append ("} / r / n "); return sb.tostring ();} 4. Generate the implementation method of the stored procedure and the return result method The parameters of the stored procedure are also detailed in the syscolumns table, and each parameter is also recorded, but I don't consider the direction of the parameters in this function. Of course, it is not very troublesome to consider going in.

Private String Buildspexec (DataSet DS) {StringBuilder SB = New StringBuilder (); String StrfuncParam = ""; Foreach (DATAROW DR IN DS.TABLES [0] .rows) {Int ITYPE = (BYTE) DR ["xipe"]; string strName = UpFirstChar (. dr [ "name"] ToString () TrimStart ( '@').); string strType = getType (iType); string strSqlType = getSqlDBType (iType); string strShortType = getTypeShort (iType); strFuncParam = strFuncParam "/ r / n / t / t" strType "a" strShortType strName ",";} strFuncParam = strFuncParam.TrimEnd ( ','); string strDef = "public bool ExeSP_" strTableName "(" StrfuncParam ") / r / n"; sb.append (strdef); sb.append ("{/ r / n"); sb.append ("/ tsqlconnection conn = sqlconn.instance (). Connection ; / r / n "); sb.append (" / r / n "); sb.append (" / tstring strspname = / "" str / n "); sb.append ( "/ tsqlcommand command = new sqlcommand (strspname, conn); / r / n"); sb.append ("/ tcommand.commandtype = commandtype.storedProcedure; / r / n"); sb.append ("/ R / N "); Foreach (DATAROW DR IN DS.TABLES [0] .ROWS) {INT ITYPE = (Byte) DR [" xtype "]; string strparaname = DR [" name "]. Tostring (); string strname = UpFirstChar (strParaName.TrimStart ( '@')); string strSqlType = getSqlDBType (iType); string strShortType = getTypeShort (iType); string strvalue = "a" strShortType strName; int iLen = (Int16) dr [ "prec "]; String strlen =

""; If (strshorttype == "Str") strlen = strn "," Ilen; string strandsmandadd = "/tcommand.parameters.add(/" " strparaname " / "," strsqltype strlen " ); / r / n "; string strcommandvalue =" /tcommand.parameters[/ "" strparaname "/"].value=" strign "; / r / n"; string strandsmandnull = "/TCommand.Parameters [/ "" strparaname "/"].value= dbnull.value; / r / n"; sb.append (strcommandadd); if (strshorttype == "dt") sb.append ("/ TIF (" Strvalue "! = DATETIME.MINVALUE) / R / N / T"); Else IF (str ") sb.append (" / tif (" strValue "! = null) / r / n / T "); Else If (strshorttype ==" img ") sb.append (" / TIF (" strValue "! = null) / r / n / t "); else sb.append (" "); SB .Append (strcommandValue); if (strshorttype == "dt" || strshorttype == "str" ​​|| strshorttype == "img") {sb.append ("/ telse / r / n / t"); SB. Append (strcommandnull);} sb.append ("/ r / n");} sb.append (addcatchString ()); sb.append ("} / r / n"); return sb.toString (); } For the stored procedure generation result sets as follows: Private string buildspgetdata (Dataset DS) {StringBuilder SB = New StringBuilder (); string strfuncparam = ""; foreach (DATAROW DR IN DS.TABLES [0] .rows) {Int ITYPE = (byte) DR ["xtype"]; string strname = Upfirstchar (DR ["name"

.] .ToString () TrimStart ( '@')); string strType = getType (iType); string strSqlType = getSqlDBType (iType); string strShortType = getTypeShort (iType); strFuncParam = strFuncParam "/ r / n / t / t " strType " a " strShortType strName ", ";} strFuncParam = strFuncParam.TrimEnd ( ','); string strDef =" public DataSet QuerySP_ " strTableName " ( " strFuncParam ") / r / N "; sb.append (strdef); sb.append (" {/ r / n "); sb.append (" / tsqlconnection conn = sqlconn.instance (); connection; / r / n "); SB. Append ("/ r / n"); sb.append ("/ tstring strspname = /" " strablename " / "; / r / n"); sb.append ("/ tsqlcommand command = new sqlcommand (strspname, CONN); / r / n "); sb.append (" / tcommand.commandtype = commandtype.storedProcedure; / r / n "); sb.append (" / r / n "); Foreach (DataRow Dr in DS. Tables [0] .ROWS) {INT ITYPE = (Byte) DR ["xtype"]; string strparaname = DR ["name"]. TOSTRING (); string strname = Upfirstchar (strparaname.trimstart ('@')); String strsqltype = getsqldbtype (iTYPE); string strshorttype = gettypeshort (iTYPE); String strign = "a" strshorttype strname; int = ("prec" = (int16) DR ["prec"]; string strlen = ""; if (string " ) Strlen = strlen "," Ilen; string strcommandadd = "/tcommand.parameters.add(/" " strparaname " / "," strsqltype strlen ");

/ r / n "; string strcommandvalue =" /tcommand.parameters[/ "" strparaname "/"].value=" strign "; / r / n"; string strcommandnull = "/TCommand.Parameters[/ " strparaname " /"].value= dbnull.value; / r / n "; sb.append (strcommandadd); if (strshorttype ==" dt ") sb.append (" / tif (" Strvalue "! = DATETIME.MINVALUE) / R / N / T"); Else IF (str ") sb.append (" / TIF (" strValue "! = Null) / r / n / t " Else IF (strshorttype == "img") sb.append ("/ TIF (" strValue "! = Null) / r / n / t"); else sb.append (""); sb.append (strcommandValue); if (strshorttype == "dt" || strshorttype == "str" ​​|| strshorttype == "img") {sb.append ("/ telse / r / n / t"); sb.append ( STRCOMMANDNULL);} sb.append ("/ r / n");} sb.append ("/ tsqldataadapter sdaresis = new sqldataadapter (command); / r / n"); sb.append ("/ tdataaset ds = new dataset (); / r / n "); sb.append (addcatchQueryString ()); sb.append ("} / r / n "); return sb.tostring ();} The following is the result of the result set: PUBL ic DataSet QuerySP_ddms_GetBank (int aiPrsn_id) {SqlConnection conn = SqlConn.Instance () Connection;. string strSPName = "ddms_GetBank"; SqlCommand command = new SqlCommand (strSPName, conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add ("@PRSN_ID", SQLDBTYPE.INT); Command.Parameters ["@ PRSN_ID"]. Value =

aiPrsn_id; SqlDataAdapter sdaResult = new SqlDataAdapter (command); DataSet ds = new DataSet (); try {sdaResult.Fill (ds);} catch (Exception e) {throw (new Exception ( "Error in the Database" e.Message ); Finally {sdaresis ();} Return DS;} There are two functions available in the program, as shown: private string addcatchstring () {StringBuilder SB = New StringBuilder (); sb.append "/ TTRY / R / N"); sb.append ("/ t {/ r / n"); sb.append ("/ t / tconn (); / r / n"); sb.append ( "/Tcommand.executenonQuery (); / r / n"); sb.append ("/ t / Treturn True; / R / N"); sb.append ("/ t} / r / n"); Sb.append ("/ Tcatch (Exception E) / R / N"); sb.append ("/ t {/ r / n"); sb.append ("/ T / TTHROW (New Exception (/" Error In The Database / " E.MESSAGE)); / R / N"); sb.append ("/ t} / r / n"); sb.append ("/ tfinal / r / n"); sb.append ("/ t {/ r / n"); sb.append ("/ t / tconn.close (); / r / n"); sb.append ("/ t} / r / n"); return SB .Tostring (); EW stringbuilder (); sb.append ("/ ttry / r / n"); sb.append ("/ t {/ r / n"); sb.append ("/ t / tsdaresisult.fill (DS); / R / N "); sb.append (" / t} / r / n "); sb.append (" / tcatch (exception E) / r / n "); sb.append (" / t {/ r / n "); sb.append (" / T / TTHROW (NEW EXCEPTION); / R / N "); Sb.Append (" / t} / r / n "); sb.append (" / tfinal / r / n "); sb.append (" / t {/ r / n "); sb.append (" / t / tsdaresisult.dispose (); / r / n "); sb.append (" / t} / r / n "); sb.append ("

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

New Post(0)