This method comes to hubbledotnetSource codeMethod
Path: Hubble. Data --> Hubble. sqlclient --> buildsqlwithsqlparameter method in the hubblecommand class
Thank you for choosing eaglet.
View code
# Region Static Methods Private Static String Buildsqlwithsqlparameter ( String SQL, system. Data. Common. dbparameter [] paras) {system. Data. Common. dbparameter [] arrparas = New System. Data. Common. dbparameter [paras. Length]; For ( Int I = 0 ; I <paras. length; I ++ ) {Arrparas [I] = Paras [I];} array. Sort (arrparas, New Dbparameterforsort ()); Object [] Objparas = New Object [Arrparas. Length]; For ( Int I = 0 ; I <arrparas. length; I ++ ) {SQL = SQL. Replace (arrparas [I]. parametername, " { " + I. tostring () + " } " ); Switch (Arrparas [I]. dbtype ){ Case System. Data. dbtype. ansistring: Case System. Data. dbtype. ansistringfixedlength: Case System. Data. dbtype. String: If (Arrparas [I]. value = Null ) {Objparas [I] = Null ;} Else {Objparas [I] = Arrparas [I]. value ;} Break ; Case System. Data. dbtype. stringfixedlength: Case System. Data. dbtype. xml: objparas [I] = Arrparas [I]. Value As String ; Break ; Case System. Data. dbtype. boolean: If (Arrparas [I]. value = Null ) {Objparas [I] = Null ;} Else {Objparas [I] = Arrparas [I]. value. tostring ();} Break ; Case System. Data. dbtype. Date: If (Arrparas [I]. value = Null ) {Objparas [I] = Null ;} Else {Objparas [I] = (Datetime) arrparas [I]. Value). tostring ( " Yyyy-mm-dd " );} Break ; Case System. Data. dbtype. datetime: Case System. Data. dbtype. datetime2: If (Arrparas [I]. value = Null ) {Objparas [I] = Null ;} Else {Objparas [I] = Convert. todatetime (arrparas [I]. value ); // (Datetime) arrparas [I]. Value). tostring ("yyyy-mm-dd hh: mm: SS "); } Break ; Case System. Data. dbtype. Time: If (Arrparas [I]. value =Null ) {Objparas [I] = Null ;} Else {Objparas [I] = (Datetime) arrparas [I]. Value). tostring ( " Hh: mm: SS " );} Break ; Case System. Data. dbtype. byte: Case System. Data. dbtype. uint16: Case System. Data. dbtype. uint32: Case System. Data. dbtype. uint64: If (Arrparas [I]. value = Null ) {Objparas [I] = Null ;} Else {Objparas [I] = Ulong . Parse (arrparas [I]. value. tostring ());} Break ; Case System. Data. dbtype. Decimal: Case System. Data. dbtype. Double: Case System. Data. dbtype. Single: If (Arrparas [I]. value = Null ) {Objparas [I] = Null ;} Else {Objparas [I] = Double . Parse (arrparas [I]. value. tostring ());} Break ; Case System. Data. dbtype. int16: Case System. Data. dbtype. int32: Case System. Data. dbtype. int64: Case System. Data. dbtype. sbyte: If (Arrparas [I]. value = Null ) {Objparas [I] =Null ;} Else {Objparas [I] = Long . Parse (arrparas [I]. value. tostring ());} Break ; Default : Throw New System. Data. dataexception (String . Format ( " Invalid parameter datatype: {0} " , Arrparas [I]. dbtype ));}} Return Buildsql (SQL, objparas );} Class Dbparameterforsort: icomparer <system. Data. Common. dbparameter> { # Region Icomparer <dbparameter> Members Public Int Compare (system. Data. Common. dbparameter X, system. Data. Common. dbparameter y ){ Return Y. parametername. compareto (X. parametername );} # Endregion } Public Static String Buildsql ( String SQL, Object [] Paras ){ If (Paras =Null ){ Return SQL ;} Else { Object [] Parameters = New Object [Paras. Length]; paras. copyto (parameters, 0 ); For ( Int I =0 ; I <parameters. length; I ++ ){ Object OBJ = Parameters [I]; If (OBJ = Null ) {Parameters [I] = " Null " ;} Else If (OBJIs String ) {Parameters [I] = String . Format ( " '{0 }' " ,(( String ) OBJ). Replace ( " ' " , " '' " ));} Else If (OBJ Is Bool ) {Parameters [I] = String . Format ( " '{0 }' " , OBJ );} Else If (OBJ Is Datetime) {parameters [I] = String . Format ( " '{0 }' " , (Datetime) OBJ). tostring ( " Yyyy-mm-dd hh: mm: SS " ));} Else If (OBJ Is Byte []) {Stringbuilder sb = New Stringbuilder (); sb. append ( " 0x " ); Foreach ( Byte B In ( Byte []) OBJ) {sb. appendformat ( " {0: X1} " , B);} parameters [I] = SB. tostring ();} Else {Parameters [I] = OBJ. tostring ();}} Return String . Format (SQL, parameters );}} # Endregion