2024年2月20日发(作者:)
三层架构之数据库访问层完全篇(C#) 三层架构之数据库访问层完全篇(C#) using System; using ; using ent; using uration; namespace DbBase ... {{"Fieldsofbasecalss"#region"Fieldsofbasecalss"protectedstaticstringstrConn=tings["strConnection"];protectedstaticstringstrSQL;#endregion"Propertiesofbaseclass"#region"Propertiesofbaseclass"}#endregion"Functionsofbaseclass"#region"Functionsofbaseclass"publicBase()...{////TODO:Addconstructorlogichere//}/**///////executingSQLcommands//////string///returnintprotectedstaticintExecuteSql(stringstrSQL)...{SqlConnectionmyCn=newSqlConnection(strConn);SqlCommandmyCmd=newSqlCommand(strSQL,myCn);{();eNonQuery();return0;}catch(eptione)...{thrownewException(e);}{e();();
{();}}/**///////getsinglevalue//////(string)///(int)protectedstaticintExecuteSql4Value(stringstrSQL)...{SqlConnectionmyCn=newSqlConnection(strConn);SqlCommandmyCmd=newSqlCommand(strSQL,myCn);{();objectr=eScalar();if((r,null))...{thrownewException("valueunavailable!");}{return(int)r;}}catch(eptione)...{thrownewException(e);}{e();();}}/**///////getobject//////(string)///(object)protectedstaticobjectExecuteSql4ValueEx(stringstrSQL)...{SqlConnectionmyCn=newSqlConnection(strConn);SqlCommandmyCmd=newSqlCommand(strSQL,myCn);{();objectr=eScalar();if((r,null))...{thrownewException("objectunavailable!");}
{returnr;}}catch(eptione)...{thrownewException(e);}{e();();}}/**///////executemultipulSQLcommands//////string///intprotectedstaticintExecuteSqls(string[]strSQLs)...{SqlConnectionmyCn=newSqlConnection(strConn);SqlCommandmyCmd=newSqlCommand();intj=;{();}catch(eptione)...{thrownewException(e);}SqlTransactionmyTrans=ransaction();{
发布评论