gpt4 book ai didi

c# - 为什么在ASP中的上下文中不存在The name…的编译错误?

转载 作者:行者123 更新时间:2023-12-02 11:04:46 25 4
gpt4 key购买 nike

我在asp.net应用程序中不断收到错误消息“名称(x)在当前上下文中不存在”。我知道我必须在包含指向我的cs文件的include指令中包含正确的<% Page声明,并且继承必须与我在其中定义的相同类。但是似乎我仍然缺少一些东西。我已经搜索了一段时间,试图找到缺少的东西,但是我所看到的大多数东西似乎都与我的特定问题无关。有人需要帮助吗?

我在.aspx文件中的代码(部分内容):

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="App_Code/Logon.aspx.cs"   Inherits="_Logon" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="loginmat" runat="server">
<div>
<asp:Label ID="matInicial" runat="server" AssociatedControlID="inptMat" Text="Ingrese su matrícula:"></asp:Label>
<asp:TextBox ID="inptMat" runat="server"></asp:TextBox>
<asp:CheckBox ID="chkPersist" runat="server" /><br />
<asp:Button ID="sbmtMat" runat="server"

并在aspx.cs文件中:
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;
using System.Data;
using System.Web.Security;

/// <summary>
/// Summary description for Logon
/// </summary>
///
public class _Logon : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void LoginBtnClick(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conMatriculas"].ConnectionString);
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText="SELECT matricula FROM dbo.Usuarios WHERE matricula=@mat";
cmd.Parameters.AddWithValue("@mat", inptMat.Text);

查询中的最后一个变量是应用程序无法达到的。

最佳答案

好像您缺少 namespace :

namespace YourNameSpace
{
public class _Logon : System.Web.UI.Page
{
...........

关于c# - 为什么在ASP中的上下文中不存在The name…的编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20007275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com