系统堆栈溢出异常

发布于 2024-08-10 20:00:55 字数 874 浏览 8 评论 0原文

请帮助我解决 System.StackOverflowException 我正在设计一个 .aspx 将记录写入数据库,我使用 4 层架构来实现这一点,一切正常,但是当我编译页面时,它会显示要插入数据的字段,当我将数据插入到这些字段并单击时提交按钮然后显示 System.StackOverflowException 发生

public class Customers
{
    public Customers()
    {
        int CustomerID = 0;
        string Fname = string.Empty;
        string Lname = string.Empty;
        string Country = string.Empty;
    }
    public int CustomerID
    {
        get { return CustomerID; }
        set { CustomerID = value; }
    }
    public string Fname
    {
        get { return Fname; }
        set { Fname = value; }****
    }
    public string Lname
    {
        get { return Lname; }
        set { Lname = value; }
    }
    public string Country
    {
        get { return Country; }
        set { Country = value; }
    }

当页面执行时弹出并显示一个窗口 System.StackOverflowException 发生请给我解决此问题的任何人

please help me regarding System.StackOverflowException
i m desing a .aspx to write records into the database i used 4-tier archietecture to implement this everything are working but when im compiling the page then its displyae the fields to insert the data ,when i insert the data to those field and clik the submitt button then its showes System.StackOverflowException occured

public class Customers
{
    public Customers()
    {
        int CustomerID = 0;
        string Fname = string.Empty;
        string Lname = string.Empty;
        string Country = string.Empty;
    }
    public int CustomerID
    {
        get { return CustomerID; }
        set { CustomerID = value; }
    }
    public string Fname
    {
        get { return Fname; }
        set { Fname = value; }****
    }
    public string Lname
    {
        get { return Lname; }
        set { Lname = value; }
    }
    public string Country
    {
        get { return Country; }
        set { Country = value; }
    }

When page is executing a window is popuped and displayed System.StackOverflowException occured please give me anyone solution to this problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月亮坠入山谷 2024-08-17 20:00:55
public int CustomerID
{
    get { return CustomerID; }
    set { CustomerID = value; }
}

您正在递归地将值分配给自身。其他属性也是如此。

您需要使用其他名称定义备份字段,例如:

private int _CustomerId;
public int CustomerID
{
    get { return _CustomerID; }
    set { _CustomerID = value; }
}

或者更好:

public int CustomerId {get; set;}
public int CustomerID
{
    get { return CustomerID; }
    set { CustomerID = value; }
}

You are assigning the value to itself recursively. And the same for the other properties.

You need to define a backup field with another name, for example:

private int _CustomerId;
public int CustomerID
{
    get { return _CustomerID; }
    set { _CustomerID = value; }
}

Or even better:

public int CustomerId {get; set;}
深海夜未眠 2024-08-17 20:00:55

请尝试以下操作:

public class Customers
{

    private int _CustomerID; 
    private string _Fname;
    private string _Lname;
    private string _Country;

    public Customers()    
    {        
        int CustomerID = 0;        
        string Fname = string.Empty;        
        string Lname = string.Empty;        
        string Country = string.Empty;    
    }    

    public int CustomerID    
    {        
        get { return _CustomerID; }        
        set { _CustomerID = value; }    
    }    

    public string Fname    
    {        
        get { return _Fname; }        
        set { _Fname = value; }
    }    

    public string Lname    
    {        
        get { return _Lname; }        
        set { _Lname = value; }    
    }    

    public string Country    
    {        
        get { return _Country; }        
        set { _Country = value; }    
    }

Try the following:

public class Customers
{

    private int _CustomerID; 
    private string _Fname;
    private string _Lname;
    private string _Country;

    public Customers()    
    {        
        int CustomerID = 0;        
        string Fname = string.Empty;        
        string Lname = string.Empty;        
        string Country = string.Empty;    
    }    

    public int CustomerID    
    {        
        get { return _CustomerID; }        
        set { _CustomerID = value; }    
    }    

    public string Fname    
    {        
        get { return _Fname; }        
        set { _Fname = value; }
    }    

    public string Lname    
    {        
        get { return _Lname; }        
        set { _Lname = value; }    
    }    

    public string Country    
    {        
        get { return _Country; }        
        set { _Country = value; }    
    }
怪我鬧 2024-08-17 20:00:55

    public Customers()
    {
        int CustomerID = 0;
        string Fname = string.Empty;
        string Lname = string.Empty;
        string Country = string.Empty;
    }
public int CustomerID { get; set; }
public string Fname { get; set; }
public string Lname { get; set; }
public string Country { get; set; }
}


    public Customers()
    {
        int CustomerID = 0;
        string Fname = string.Empty;
        string Lname = string.Empty;
        string Country = string.Empty;
    }
public int CustomerID { get; set; }
public string Fname { get; set; }
public string Lname { get; set; }
public string Country { get; set; }
}

眼波传意 2024-08-17 20:00:55

您的属性 Get & 中有无限递归调用设置如下:

string Lname{ 
    get { return Lname; } 
    set { Lname = value; }
} 

Lname = value;将再次致电您的物业&再次。

there is infinite recusrive calls in your properties Get & Set like:

string Lname{ 
    get { return Lname; } 
    set { Lname = value; }
} 

Lname = value; will call your property again & again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文