C # obtain a stored procedure that returns a result set and a returned value

Source: Internet
Author: User

String View_Name = ""; try {// put the user code here to initialize the page String DBConnStr; DataSet MyDataSet = new DataSet (); System. data. sqlClient. sqlDataAdapter DataAdapter = new System. data. sqlClient. sqlDataAdapter (); string serverIP = ConfigurationManager. appSettings ["ServerIP"]; string serverUser = ConfigurationManager. appSettings ["ServerUser"]; string dbName = ConfigurationManager. appSettings ["DbName"]; string userPw D = ConfigurationManager. appSettings ["UserPwd"]; DBConnStr = "server =" + serverIP + "; database =" + dbName + "; pwd =" + userPwd + "; uid = "+ serverUser +" "; System. data. sqlClient. sqlConnection myConnection = new System. data. sqlClient. sqlConnection (DBConnStr); if (myConnection. state! = ConnectionState. open) {myConnection. open ();} System. data. sqlClient. sqlCommand myCommand = new System. data. sqlClient. sqlCommand ("GetXiaFa_Record_Tow", myConnection); myCommand. commandType = CommandType. storedProcedure; // Add the input query parameter and assign the value myCommand. parameters. add ("@ PipeIDs", SqlDbType. varChar); myCommand. parameters ["@ PipeIDs"]. value = pips; myCommand. parameters. add ("@ DateStart", SqlDbType. varChar); m YCommand. parameters ["@ DateStart"]. value = sbutract; myCommand. parameters. add ("@ DateEnd", SqlDbType. varChar); myCommand. parameters ["@ DateEnd"]. value = currentDate; myCommand. parameters. add ("@ cnt", SqlDbType. varChar); myCommand. parameters ["@ cnt"]. value = cnt; myCommand. parameters. add ("@ Status", SqlDbType. varChar); myCommand. parameters ["@ Status"]. value = SendStatus; myCommand. parameters. add ("@ Destina Tion_no ", SqlDbType. varChar); myCommand. parameters ["@ Destination_no"]. value = this.txt Desno. text; myCommand. parameters. add ("@ Sms_SendContents", SqlDbType. varChar); myCommand. parameters ["@ Sms_SendContents"]. value = this.txt SmsContents. text; myCommand. parameters. add ("@ user_code", SqlDbType. varChar); myCommand. parameters ["@ user_code"]. value = selectUser; myCommand. parameters. add ("@ MessageType", SqlDb Type. varChar); myCommand. parameters ["@ MessageType"]. value = "1"; myCommand. parameters. add ("@ IsStatus", SqlDbType. varChar); myCommand. parameters ["@ IsStatus"]. value = userInfo. isStatus; myCommand. parameters. add ("@ pageIndex", SqlDbType. varChar); myCommand. parameters ["@ pageIndex"]. value = this. pageInfo. currentPageIndex-1; myCommand. parameters. add ("@ pageSizes", SqlDbType. varChar); myCommand. parameter S ["@ pageSizes"]. value = this. pageInfo. pageSize; // Add the output parameter myCommand. parameters. add ("@ view_name", SqlDbType. varChar, 50); myCommand. parameters ["@ view_name"]. direction = ParameterDirection. output; myCommand. executeNonQuery (); DataAdapter. selectCommand = myCommand; DataAdapter. fill (MyDataSet, "table"); // obtain the number of data entries if (MyDataSet! = Null & MyDataSet. tables. count> 0) {for (int I = 0; I <MyDataSet. tables [0]. rows. count; I ++) {PageCount + = int. parse (MyDataSet. tables [0]. rows [I] ["Counts"]. toString () ;}} MyDataSet. dispose (); // get the Stored Procedure output parameter View_Name = myCommand. parameters ["@ view_name"]. value. toString (); if (myConnection. state = ConnectionState. open) {myConnection. close () ;}} catch (Exception ex) {Base. writeErrorLog ("query of issued records An error occurred while creating the view within 3 days: "+ ex. message. replace (Environment. newLine, string. empty), HttpContext. current. server. mapPath ("ErrorLog \");} if (View_Name! = "") {Dictionary <string, object> dicTo = new Dictionary <string, object> (); dicTo. add ("viewName", View_Name); dicTo. add ("pageIndex", int. parse (this. pageInfo. currentPageIndex. toString ()-1); dicTo. add ("pageSizes", this. pageInfo. pageSize); DataSet ds = Base. getDataSet ("dbo. getXiaFa_Record_View ", dicTo); if (ds! = Null & ds. Tables. Count> 0) {dt2 = ds. Tables [0] ;}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.