存儲過程 兩種方法的實例

来源:http://www.cnblogs.com/shouce/archive/2016/01/07/5108052.html
-Advertisement-
Play Games

protected void btnSend_Click(object sender, EventArgs e) 2: { 3: int temp = -1; 4: int exhibitionID = int.Parse(Request.QueryString["Con...


protected void btnSend_Click(object sender, EventArgs e)
   2: {
   3:     int temp = -1;
   4:     int exhibitionID = int.Parse(Request.QueryString["ConList"]);
   5:     int exhibitorType = 0;
   6:     
   7:     int mCustomerID = 0;
   8:     if (Session["UserID"] != null)
   9:     {
  10:         ViewState["CID"] = myShare.GetAObject(true, 1, "CustomerID", "Customers", "UserID='" + Session["UserID"].ToString() + "'").ToString();
  11:         if (!string.IsNullOrEmpty(ViewState["CID"].ToString()))
  12:         {
  13:             mCustomerID = Convert.ToInt32(ViewState["CID"].ToString());
  14:         }
  15:     }
  16:     string company = this.txtCompay.Text.Trim();
  17:     string name = this.txtName.Text;
  18:     string tel = this.txtTel.Text;
  19:     string email = this.txtEmail.Text;
  20:  
  21:     SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
  22:  
  23:     SqlCommand com = new SqlCommand("ExpoApply", con);
  24:     com.CommandType = CommandType.StoredProcedure;
  25:  
  26:     SqlParameter parCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int);
  27:     parCustomerID.Value = mCustomerID;
  28:     com.Parameters.Add(parCustomerID);
  29:  
  30:     SqlParameter parCompanyName = new SqlParameter("@CompanyName", SqlDbType.NVarChar, 100);
  31:     parCompanyName.Value = company;
  32:     com.Parameters.Add(parCompanyName);
  33:  
  34:     SqlParameter parContact = new SqlParameter("@Contact", SqlDbType.VarChar, 50);
  35:     parContact.Value = name;
  36:     com.Parameters.Add(parContact);
  37:  
  38:     SqlParameter parEmail = new SqlParameter("@Email", SqlDbType.VarChar, 50);
  39:     parEmail.Value = email;
  40:     com.Parameters.Add(parEmail);
  41:  
  42:  
  43:     SqlParameter parReturnValue = new SqlParameter("@ReturnValue", SqlDbType.Int);
  44:     parReturnValue.Direction = ParameterDirection.Output;
  45:     com.Parameters.Add(parReturnValue);
  46:  
  47:     try
  48:     {
  49:         con.Open();
  50:         com.ExecuteNonQuery();
  51:  
  52:         temp = int.Parse(com.Parameters["@ReturnValue"].Value.ToString());
  53:  
  54:         if (temp == -1)
  55:         {
  56:             myShare.WebMessageBox(this.Page, "信息發佈時出錯,請重試!");
  57:         }
  58:         else if (temp == 0)
  59:         {
  60:             myShare.WebMessageBox(this.Page, "信息發佈失敗,請重試!");
  61:         }
  62:         else
  63:         {
  64:             ClientScript.RegisterStartupScript(ClientScript.GetType(), "提示", "<script>alert('信息發佈成功!');window.location='DiscountExpoList.aspx'</script>");
  65:         }
  66:  
  67:     }
  68:     catch (Exception ex)
  69:     {
  70:         Response.Write(ex.Message);
  71:     }
  72:  
  73: }

  

1: SqlConnection con = null;
   2: try
   3: {
   4:     con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
   5:     SqlCommand com = new SqlCommand();
   6:     com.Connection = con;
   7:     com.CommandType = CommandType.StoredProcedure;
   8:     com.CommandText = "ExpoApply";
   9:     con.Open();
  10:     SqlParameter[] sp = 
  11:      {
  12:          new SqlParameter("@CustomerID",SqlDbType.Int)
  13:          ,new SqlParameter("@CompanyName",SqlDbType.NVarChar,100)
  14:          ,new SqlParameter("@Contact",SqlDbType.VarChar,50)
  15:          ,new SqlParameter("@Email",SqlDbType.VarChar,50)
  16:          //...   
  17:          ,new SqlParameter("@ReturnValue",SqlDbType.Int)
  18:  
  19:       };
  20:     sp[0].Value = mCustomerID;
  21:     sp[1].Value = company;
  22:     sp[2].Value = name;
  23:     sp[3].Value = email;
  24:     //  ...
  25:     sp[16].Direction = ParameterDirection.Output;
  26:     com.Parameters.AddRange(sp);
  27:     com.ExecuteNonQuery();
  28:     temp = Convert.ToInt32(com.Parameters["@ReturnValue"].Value);
  29:     con.Close();
  30: }
  31:  
  32: catch (SqlException se)
  33: {
  34: }
  35: finally
  36: {
  37:     con.Close();
  38: }
  39:  
  40: if (temp == -1)
  41: {
  42:     myShare.WebMessageBox(this.Page, "信息發佈時出錯,請重試!");
  43: }
  44: else if (temp == 0)
  45: {
  46:     myShare.WebMessageBox(this.Page, "信息發佈失敗,請重試!");
  47: }
  48: else
  49: {
  50:     ClientScript.RegisterStartupScript(ClientScript.GetType(), "提示", "<script>alert('信息發佈成功!');window.location='DiscountExpoList.aspx'</script>");
  51: }

  


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 很多創業型企業,都是追求快速把產品推向市場。也因這個因素,在設計和研發過程中,往往追求快為目標,在架構選型、代碼編寫等環節往往疏忽了性能的考慮。但這種現象是屬於正常的,一個好的產品是在客戶使用下不斷重構成長起來的。 產品的長期運行中,會隨著數據的不斷龐大、操作用戶的不斷增加及網路慢等元素,會慢慢.....
  • 不廢話,直接上代碼,您也可以點這裡看瀑布流效果演示。前臺:getMyVal('category',$_GET);$xiaohuaList=Xiaohua::model()->getXiaohao($category); //打開頁面預設顯示的數據?> id;?> ">title);?> ...
  • 最近在學python,正好遇到學校需要選宿舍,就用python寫了一個搶宿舍的軟體。其中有一個模塊是用來登陸的,登陸的時候需要輸入驗證碼,不過後來發現了直接可以繞過驗證碼直接登陸的bug。不過這是另外的話題,開始的時候我並沒有發現這個隱藏起來的秘密,所以我就寫了這個python代碼段用來實現解析驗證...
  • //#include#include#includestruct Word //定義結構數組儲存單詞{ char w[20]; int num;}Word[10000];void main() ...
  • class FileUtils{ //文件目錄下文件總數目 public static int fileNumber(File dir) { int filenumber = 0; if(dir.exists()) { ...
  • 在 FMX 下的 TComboBox 下拉菜單字型修改有二種方法:使用 Style,需先設定好 Style 後,再指定預設項的 Style,方法如下:procedure TForm1.FormCreate(Sender: TObject);var i: Integer;begin Combo...
  • String和StringBuffer、StringBuilder的區別
  • 第一節 介面慨述 介面(interface)用來定義一種程式的協定。實現介面的類或者結構要與介面的定義嚴格一致。有了這個協定,就可以拋開編程語言的限制(理論上)。介面可以從多個基介面繼承,而類或結構可以實現多個介面。介面可以包含方法、屬性、事件和索引器。介面本身不提供它所定義的成員的實現。介面只指....
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...