2012-02-24 56 views
3

我想我在我的類中缺少'USING'語句,因爲當我嘗試將commandType設置爲存儲過程時出現錯誤。的CommandType = '智能感知無法找到' CommandType.StoredProcedure(注:該功能僅在部分粗加工)在此先感謝使用存儲過程和ADO.NET更新數據庫

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Configuration; 
using System.Data.SqlClient; 


namespace LegacyForms.Personal 
{ 
    public partial class FormBuilder : System.Web.UI.Page 
    { 
     protected void btnSubmit_Click(object sender, EventArgs e) 
     { 
      //Get the DB connection: 
      string ConnString = ConfigurationManager.AppSettings["AssociatedBank2011ConnectionString"]; 
      SqlConnection conn = new SqlConnection(ConnString); 



     SqlCommand cmd = new SqlCommand("uspInsertPersonalAccountApplcation", conn); 
     cmd.Commandtype = **get error here!** 
     cmd.Parameters.AddWithValue("@AccountType", AcctType); 
     cmd.Parameters.AddWithValue("@AccountSubType", AcctSubType); 
     cmd.Parameters.AddWithValue("@CheckingOption", CheckOption); 

     conn.Open(); 
     cmd.ExecuteNonQuery(); 

     conn.Close(); 
    } 
} 

}

回答

1

我也建議其他using聲明爲您SqlConnectionSqlCommand對象。由於它們都實現了IDisposable接口,您可以執行以下操作:

string ConnString = ConfigurationManager.AppSettings["AssociatedBank2011ConnectionString"]; 
using (SqlConnection conn = new SqlConnection(ConnString)) 
using (SqlCommand cmd = new SqlCommand("uspInsertPersonalAccountApplcation", conn)) 
{ 
    cmd.Commandtype = CommandType.StoreProcedure; 
    cmd.Parameters.AddWithValue("@AccountType", AcctType); 
    cmd.Parameters.AddWithValue("@AccountSubType", AcctSubType); 
    cmd.Parameters.AddWithValue("@CheckingOption", CheckOption); 

    conn.Open(); 
    cmd.ExecuteNonQuery(); 
} 

這樣的話,在你的代碼工作正常拋出一個異常,在使用塊,你SqlConnectionSqlCommand將清理情況之後。

0

在這種情況下,您可以按CTRL +。 (ctrl + dot)得到一個建議,你想使用System.Data添加...

P.S.教一個男人去釣魚...