【网学网提醒】:网学会员鉴于大家对十分关注,论文会员在此为大家搜集整理了“SQL异步执行技术”一文,供大家参考学习
usingSystem;usingSystem.Collections.Generic;usingSystem.Web;usingSystem.Data.SqlClient;namespaceMyDb{publicclassInputLogOnRecord{publicInputLogOnRecord(){}privatestaticstringconnectionStr="PersistSecurityInfo=False;AsynchronousProcessing=true;IntegratedSecurity=True;database=DB;server=(local)";privatestaticstringrecordTableName="UserLoginRecord";publicstaticvoidInput(string[]inputArray){SqlConnectionsqlConnection=newSqlConnection(connectionStr);try{sqlConnection.Open();}catch(Exceptionex){stringerrorStr=ex.Message;}SqlCommandsqlCommand=newSqlCommand();sqlCommand.Connection=sqlConnection;stringcmdText=getRecordText(inputArray);sqlCommand.CommandText=cmdText;try{IAsyncResultasyncResultsqlCommand.BeginExecuteNonQuery(inputRecordAsync,sqlCommand);}catch(Exceptionex){=
stringerrorStr=ex.Message;sqlConnection.Close();}}privatestaticstringgetRecordText(string[]inputArray){stringcmdText="";foreach(stringinputininputArray){cmdText=cmdText+"'"+input+"',";}cmdText="insertinto"+recordTableName+"values("+cmdText.Substring(0,cmdText.Length-1)+")";returncmdText;}privatestaticvoidinputRecordAsync(IAsyncResultar){SqlCommandsqlCommand=ar.AsyncStateasSqlCommand;intcompleteParam=sqlCommand.EndExecuteNonQuery(ar);sqlCommand.Connection.Close();}}}