2012-10-16 70 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是不够的。

相关问题