2017-01-05 2 views
0

저는 C#을 처음 사용합니다. Kudvenkat 자습서의 간단한 예제를 따라하면됩니다. http://csharp-video-tutorials.blogspot.com/2012/10/calling-stored-procedure-with-output.htmlWebForm1에 'Context'에 대한 정의가 없습니다.

오류가 계속 발생하면서 내가 뭘 잘못하고 있는지 이해할 수 없습니까?

내에서 .aspx 파일 : 내 aspx.cs에서

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1"%> 

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <table style="border: 1px solid black; font-family:Arial"> 
      <tr> 
       <td> 
        Employee Name 
       </td> 
       <td> 
        <asp:TextBox ID="txtEmployeeName" runat="server"></asp:TextBox> 
       </td> 
      </tr>   
      <tr> 
       <td> 
        Gender 
       </td> 
       <td> 
       <asp:DropDownList ID="ddlGender" runat="server"> 
        <asp:ListItem>Male</asp:ListItem> 
        <asp:ListItem>Female</asp:ListItem> 
       </asp:DropDownList> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        Salary 
       </td> 
       <td> 
        <asp:TextBox ID="txtSalary" runat="server"></asp:TextBox> 
       </td> 
      </tr>  
      <tr> 
       <td colspan="2"> 
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" /> 
       </td> 
      </tr>   
      <tr> 
       <td colspan="2"> 
        <asp:Label ID="lblMessage" runat="server"></asp:Label> 
       </td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 

이 파일 txtEmployeeName.Text, ddlGender.SelectedValue와 'txtSalary.Text은'"The name .txt does not exist in a current context"

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; 
using System.Configuration; 


namespace adoDemo 
{ 
    public partial class WebForm1 : System.Web.UI.Page 
    { 
     protected void btnSubmit_Click(object sender, EventArgs e) 

     { 
      //Read the connection string from Web.Config file 
      string ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; 
      using (SqlConnection con = new SqlConnection(ConnectionString)) 
      { 
       //Create the SqlCommand object 
       SqlCommand cmd = new SqlCommand("spAddEmployee", con); 
       //Specify that the SqlCommand is a stored procedure 
       cmd.CommandType = System.Data.CommandType.StoredProcedure; 

       //Add the input parameters to the command object 
       cmd.Parameters.AddWithValue("@Name", txtEmployeeName.Text); 
       cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedValue); 
       cmd.Parameters.AddWithValue("@Salary", txtSalary.Text); 

       //Add the output parameter to the command object 
       SqlParameter outPutParameter = new SqlParameter(); 
       outPutParameter.ParameterName = "@EmployeeId"; 
       outPutParameter.SqlDbType = System.Data.SqlDbType.Int; 
       outPutParameter.Direction = System.Data.ParameterDirection.Output; 
       cmd.Parameters.Add(outPutParameter); 

       //Open the connection and execute the query 
       con.Open(); 
       cmd.ExecuteNonQuery(); 

       //Retrieve the value of the output parameter 
       string EmployeeId = outPutParameter.Value.ToString(); 
       lblMessage.Text = "Employee Id = " + EmployeeId; 
      } 
     } 
    } 
} 

그리고 내 aspx.designer을 말한다 빨간색 밑줄이있다. CS 파일 :

//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by a tool. 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

namespace adoDemo { 


    public partial class WebForm1 { 

     /// <summary> 
     /// form1 control. 
     /// </summary> 
     /// <remarks> 
     /// Auto-generated field. 
     /// To modify move field declaration from designer file to code-behind file. 
     /// </remarks> 
     protected global::System.Web.UI.HtmlControls.HtmlForm form1; 

     /// <summary> 
     /// txtEmployeeName control. 
     /// </summary> 
     /// <remarks> 
     /// Auto-generated field. 
     /// To modify move field declaration from designer file to code-behind file. 
     /// </remarks> 
     protected global::System.Web.UI.WebControls.TextBox txtEmployeeName; 

     /// <summary> 
     /// ddlGender control. 
     /// </summary> 
     /// <remarks> 
     /// Auto-generated field. 
     /// To modify move field declaration from designer file to code-behind file. 
     /// </remarks> 
     protected global::System.Web.UI.WebControls.DropDownList ddlGender; 

     /// <summary> 
     /// txtSalary control. 
     /// </summary> 
     /// <remarks> 
     /// Auto-generated field. 
     /// To modify move field declaration from designer file to code-behind file. 
     /// </remarks> 
     protected global::System.Web.UI.WebControls.TextBox txtSalary; 

     /// <summary> 
     /// btnSubmit control. 
     /// </summary> 
     /// <remarks> 
     /// Auto-generated field. 
     /// To modify move field declaration from designer file to code-behind file. 
     /// </remarks> 
     protected global::System.Web.UI.WebControls.Button btnSubmit; 

     /// <summary> 
     /// lblMessage control. 
     /// </summary> 
     /// <remarks> 
     /// Auto-generated field. 
     /// To modify move field declaration from designer file to code-behind file. 
     /// </remarks> 
     protected global::System.Web.UI.WebControls.Label lblMessage; 
    } 
} 
+0

확인 디자이너 파일을 namespace 이름이 포함되어야합니다 이 텍스트 상자를 삭제하고 다시 작성하지 않으면 생성됨 – meda

+0

디자이너 파일을 추가했습니다. 죄송합니다. 그러나 속성이 생성되었는지 어떻게 알 수 있습니까? – Oleg

+0

실제로 거기에 그냥 깨끗한 다음 다시 시도하십시오 – meda

답변

1

이 오류는 다음과 같은 이유로 나타날 수 있습니다. 실제로 재 컴파일해야하는 것에 대해 VS가 혼동하기 때문에 mbly 캐싱 문제가 발생합니다. 그냥 delete the cache items하고 정상적으로 다시 컴파일하십시오.

디자이너 파일을보고 Visual Studio에서 컨트롤에 항목이 만들어 졌는지 확인하십시오. 유사한 선언이있는 다른 파일이 없는지 확인하십시오.

여러 번 수정하는 가장 좋은 방법은 양식을 삭제하고 다시 만들고 이름을 바꾸는 것입니다. 이후 디자이너 파일을 직접 편집하지 않아도됩니다.

+0

양식을 다시 만들고 이름을 바꿉니다. 나는 또한 VS 캐시 디렉토리를 삭제했다. 하지만 여전히 밑줄이 그어져 있습니다. txtEmployeeName.Text, ddlGender.SelectedValue 및 'txtSalary.Text'는 "이름 .txt가 현재 컨텍스트에 없습니다"라는 빨간색 밑줄이 있습니다. 나는이 언어를 싫어하기 시작했다 :) – Oleg

+0

대단히 고마워. 필자가 도운 것은 전체 프로젝트를 완전히 삭제하고 다시 만들고 가능한 모든 파일의 이름을 바꾸는 것입니다. 대단히 감사합니다! – Oleg

0

문제는

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1"%> 

그것은해야이 라인에있다

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="adoDemo.WebForm1"%> 

Inherits도 특성을 알아보기 위해 귀하의 경우, adoDemo