2012-10-16 73 views
1

嘿傢伙仍然忙於我發現的註冊表單文章,我跟着人的步驟,並插入他發佈的代碼,但我似乎得到錯誤「不存在於當前的上下文中」上午我做錯了什麼或者他的代碼是一個問題?在當前的情況下不存在註冊表格

http://www.c-sharpcorner.com/uploadfile/rohatash/simple-user-login-in-Asp-Net-using-C-Sharp/

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

public partial class StudentLogin : System.Web.UI.Page 
{ 
protected void Page_Load(object sender, EventArgs e) 
{ 

} 
protected void btnRegister_Click(object sender, EventArgs e) 
{ 
    string strcon = "Data Source=.;uid=sa;pwd=Password$2;database=master"; 
    SqlConnection con = new SqlConnection(strcon); 

    SqlCommand com = new SqlCommand("VC-Temps", con); 
    com.CommandType = CommandType.StoredProcedure; 
    SqlParameter p1 = new SqlParameter("StudCode", TextBox3.Text); 
    SqlParameter p2 = new SqlParameter("Password", TextBox4.Text); 
    SqlParameter p3 = new SqlParameter("FirstName", TextBox5.Text); 
    SqlParameter p4 = new SqlParameter("LastName", TextBox6.Text); 
    SqlParameter p5 = new SqlParameter("Telephone", TextBox7.Text); 
    SqlParameter p6 = new SqlParameter("Course", TextBox8.Text); 
    SqlParameter p7 = new SqlParameter("Availability", DropDownList1.Text); 
    SqlParameter p8 = new SqlParameter("JobSkill", DropDownList2.Text); 
    SqlParameter p9 = new SqlParameter("Experience", DropDownList3.Text); 
    com.Parameters.Add(p1); 
    com.Parameters.Add(p2); 
    com.Parameters.Add(p3); 
    com.Parameters.Add(p4); 
    com.Parameters.Add(p5); 
    com.Parameters.Add(p6); 
    com.Parameters.Add(p7); 
    com.Parameters.Add(p8); 
    com.Parameters.Add(p9); 
    con.Open(); 
    com.ExecuteNonQuery(); 

} 
} 

錯誤是:錯誤3名稱 '的CommandType' 不在當前上下文中存在C:\網站\ StudentLogin.aspx.cs 21 27 C:\網站\

回答

4

您需要提供完整的名稱空間或添加using System.Data.SqlClient

右鍵單擊CommandType並從Resolve菜單中選擇一個項目..

您也可以按下Ctrl鍵+而卡爾特是有問題的詞。

編輯:需要參考System.Data,請先檢查一下。

+0

+1,'CommandType'位於'System.Data.CommandType'命名空間中,它將出現在Resolve菜單中。 – Arrow

+0

確保你打開方法內部的連接。我愚蠢 –

0

我得到這個錯誤,因爲我在使用語句中有一個分號。花了我一段時間看到它。

using (System.Data.SqlClient.SqlCommand cmd = new SqlCommand(sql, sqlConn)); <=no no 
    { 
     cmd.CommandType = CommandType.Text; 
0

通過明確包括以下以及using System.Data.SqlClient解決礦山:

using System.Data; 

原來using System.Data.SqlClient是不夠的。

相關問題