????SQL???????
???????????? ???????[ 2015/4/14 13:53:22 ] ????????????? SQL ?? ???
????????
???????????????????Ч???????????????????????????????????????????????
??????????????????????????????????????????????д????
????????????????????????????κ?SQL-Server?????????κδ洢?????T-SQL?????????????????????????????C#?????????????????????
????????
?????????????Щ?????????????????????????????
???????
?????????????????????
????BLL(Business Logic Layer)??????MS-SQL????????????????????????????????????????????????????????????????????????????.
????DAL(Data Access Layer)??????????д???SQL?洢???????????????????????????????????????DAL??
????????????????????????DAL??
????namespace SQLWrapper
????{
????public class DAL:BLL
????{
????public DAL(string server??string db??string user??string pass)
????{
????base.Start(server??db??user??pass);
????}
????~DAL()
????{
????base.Stop(eStopType.ForceStopAll);
????}
????///////////////////////////////////////////////////////////
????//TODO:Here you can add your code here...
????}
????}
????????BLL????????????????????????????????????????????????????????????????`Stop`??????????????????????????????
????NOTE:????????????????MS-SQL????????????????BLL???е?`CreateConnectionString`?????????????????????????
??????????洢????????????DAL?б?д???????:
????public int MyStoreProcedure(int param1??string param2)
????{
????//????洢??????????????????????
????StoredProcedureCallbackResult userData=new StoredProcedureCallbackResult(eRequestType.Scalar);
????//?????崫??洢???????????????в??????????userData.Parameters=new System.Data.SqlClient.SqlParameter[]{
????new System.Data.SqlClient.SqlParameter("@param1"??param1)??
????new System.Data.SqlClient.SqlParameter("@param2"??param2)??
????};
????//Execute procedure...
????if(!ExecuteStoredProcedure("usp_MyStoreProcedure"??userData))
????throw new Exception("Execution failed");
????//?????????...
????//???????<userdata.tswaitforresult>
????//???δ??????<timeout>
????if(WaitSqlCompletes(userData)!=eWaitForSQLResult.Success)
????throw new Exception("Execution failed");
????//Get the result...
????return userData.ScalarValue;
????}
????????????????????洢??????????????????`Scalar`??`Reader`??`NonQuery`??????`Scalar`??`userData`??`ScalarValue`??????????(????????)??????`NonQuery`??`userData`??`AffectedRows`??????????????????????`Reader`?????`ReturnValue`?????????????????????????`userData`??`resultDataReader`????????recordset??
???????????????:
????public bool MySQLQuery(int param1??string param2)
????{
????//Create user data according to return type of store procedure in SQL(????????и???)
????ReaderQueryCallbackResult userData=new ReaderQueryCallbackResult();
????string sqlCommand=string.Format("SELECT TOP(1)*FROM tbl1
????WHERE code={0}AND name LIKE'%{1}%'"??param1??param2);
????//Execute procedure...
????if(!ExecuteSQLStatement(sqlCommand??userData))
????return false;
????//Wait until it finishes...
????//Note??it will wait(userData.tsWaitForResult)
????//for the command to be completed otherwise returns<timeout>
????if(WaitSqlCompletes(userData)!=eWaitForSQLResult.Success)
????return false;
????//Get the result...
????if(userData.resultDataReader.HasRows&&userData.resultDataReader.Read())
????{
????//Do whatever you want....
????int field1=GetIntValueOfDBField(userData.resultDataReader["Field1"]??-1);
????string field2=GetStringValueOfDBField(userData.resultDataReader["Field2"]??null);
????Nullable<datetime>field3=GetDateValueOfDBField(userData.resultDataReader["Field3"]??null);
????float field4=GetFloatValueOfDBField(userData.resultDataReader["Field4"]??0);
????long field5=GetLongValueOfDBField(userData.resultDataReader["Field5"]??-1);
????}
????userData.resultDataReader.Dispose();
????return true;
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11