我正在制作一个小应用程序并收到以下错误。 [英] I am making a small application and receiving following errors.

查看:55
本文介绍了我正在制作一个小应用程序并收到以下错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到下划线后面的错误



i am recieving following error on the underlined line

The name 'txtname' does not exist in the current context




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

namespace SubmitData
{
    public partial class Default : System.Web.UI.Page
    {
        submit us = new submit();
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {

            us.saveuserinfo(txtname.Text,txtpassword.Text, gender.SelectedValue, ddldegree.SelectedValue, ddlhobby.SelectedValue); // ERROR here
            
            Response.Redirect("About.aspx");
        }
    }
    
}





我的班级代码是:

我也收到了此编码中标记行的错误。





my class code is:
and i am also recieving error on marked line in this coding.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SubmitData
{
    public class submit
    {
         public bool saveuserinfo(String name,String password,String gender,String degree, String hobby)
        {

            using (var db = new saveinfoEntities())
            {
               userinfo usin = new userinfo();
                usin.name=name;
                usin.password=password;
                usin.gender=gender;
                usin.degree=degree;
                usin.hobby=hobby;
                db.userinfoes.InsertOnSubmit(usin); // ERROR here
                db.SubmitChanges();
                return true;
            }
        }
    }
}

推荐答案

这两个问题可能很漂亮大致相同:编译器找不到任何确切的名称:所以要检查两件事。

1)仔细查看文本框:它的名称与txtname完全相同?请记住,C#区分大小写,因此txtname与txtName或Txtname或TxtName不同,并且它不会发明元音,因此它与textname不同要么!

2)如果名称完全相同,现在检查申报行并确保它包含'Runat =server'属性:

The two problems are probably pretty much the same: the compiler can't find anything of that exact name: So there are two things to check.
1) Look at your text box closely: is it's name exactly the same as "txtname"? Remember that C# is case sensitive, so "txtname" is not teh same as "txtName" or "Txtname" or "TxtName", and that it won't "invent" vowels, so it isn't the same as "textname" either!
2) If the name is exactly the same, now check the declaration line and make sure it includes the 'Runat="server"' attribute:
<asp:TextBox ID="txtname" runat="server" MaxLength="6"></asp:TextBox>



如果是不修复它,然后我们需要更多的信息 - 比如页面。



然后对你的InsertOnSubmit方法做同样的事情:你需要确保db.userinfoes表示的类恰好包含该方法名称。


If that doesn't fix it, then we need more info - like the page as well.

Then do the same for your InsertOnSubmit method: you need to be sure that the class that db.userinfoes represents contains exactly that method name.


1)确保 txtname 中的控件可用于 aspx 页面。

如果可用,请将其删除并尝试再次添加。确保它在设计师页面中可用..



2)请添加对 System.Data.Linq dll

右键单击项目 - >添加参考 - >框架 - >选择System.Data.Linq.dll



根据OP的对话修改解决方案。

EDMX 文件(实体框架

所以语法应该是这样的

1) Make sure that the control txtname is available in your aspx page.
in case if it available , pls delete it and try to add it once again. make sure it is available in the designer page..

2) Please add reference to System.Data.Linq dll
right click project -> add reference -> Framework -> select System.Data.Linq.dll

Revised solution based on the OP's Conversation.
Its EDMX file ( Entity Framework )
so the syntax should be like this
db.userinfoes.Add(usin);
db.SaveChanges();


这篇关于我正在制作一个小应用程序并收到以下错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆