2012-02-24 4 views
3

저장 프로 시저에 commandType을 설정하려고하면 오류가 발생하므로 클래스에 'USING'문이 누락되었다고 생각합니다. CommandType을 =는 CommandType.StoredProcedure ', 인텔리는 찾는데 실패'(주 : 기능이 부분적으로 만 밖으로 거칠게) 사전에 감사저장 프로 시저 및 ADO.NET을 사용하여 DB 업데이트

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(); 
    } 
} 

을} 당신은 System.Data를 참조 할 필요가

답변

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 + 점) System.Data를 사용하여 추가하려는 것과 같은 제안을 받으십시오.

P.S. 남자에게 물고기를 가르쳐주세요 ...