程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#獲取一個即返回結果集,又返回值的存儲過程

C#獲取一個即返回結果集,又返回值的存儲過程

編輯:C#入門知識

string View_Name = "";
                        try
                        {
                            // 在此處放置用戶代碼以初始化頁面
                            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 userPwd = 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;
                            //添加輸入查詢參數、賦予值
                            myCommand.Parameters.Add("@PipeIDs", SqlDbType.VarChar);
                            myCommand.Parameters["@PipeIDs"].Value = pips;
                            myCommand.Parameters.Add("@DateStart", SqlDbType.VarChar);
                            myCommand.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("@Destination_no", SqlDbType.VarChar);
                            myCommand.Parameters["@Destination_no"].Value = this.txtDesno.Text;
                            myCommand.Parameters.Add("@Sms_SendContents", SqlDbType.VarChar);
                            myCommand.Parameters["@Sms_SendContents"].Value = this.txtSmsContents.Text;
                            myCommand.Parameters.Add("@user_code", SqlDbType.VarChar);
                            myCommand.Parameters["@user_code"].Value = selectUser;
                            myCommand.Parameters.Add("@MessageType", SqlDbType.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.Parameters["@pageSizes"].Value = this.PageInfo.PageSize;
                            //添加輸出參數
                            myCommand.Parameters.Add("@view_name", SqlDbType.VarChar, 50);
                            myCommand.Parameters["@view_name"].Direction = ParameterDirection.Output;


                            myCommand.ExecuteNonQuery();
                            DataAdapter.SelectCommand = myCommand;

                            DataAdapter.Fill(MyDataSet, "table");

                            //獲取數據條數
                            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();
                            //得到存儲過程輸出參數
                            View_Name = myCommand.Parameters["@view_name"].Value.ToString();
                            if (myConnection.State == ConnectionState.Open)
                            {
                                myConnection.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            Base.WriteErrorLog("下發記錄查詢3天內——創建視圖異常:" + 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];
                            }
                        }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved