System.StackOverflowException,使用获取集属性时

时间:2019-02-14 13:12:13

标签: c# sql sql-server linq devexpress

我的方法无效,我在Account上调用它,然后发生此错误

Error: System.StackOverflowException on " da.Fill(dt) ". 

我该怎么办?或如何以其他方式调用GroupedAccount()?

string fAccount;
[Key]
[Size(150)]
public string Account
{
    get { GroupedAccount(); return fAccount; }
    set { SetPropertyValue<string>(nameof(Account), ref fAccount, value); }
}
private void GroupedAccount()
        {
            SqlConnection conn = new SqlConnection("Connection");
            SqlCommand cmd = new SqlCommand("SELECT * FROM Traders", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
    conn.Open();
        var groupedData = from b in dt.AsEnumerable()
                          group b by b.Field<string>("Account Name") into g
                          select new
                          {
                              fAccounts = g.Key,
                          };

        foreach (var r in groupedData)
        {
            SqlCommand cmd2 = new SqlCommand("INSERT INTO dbo.TradersAccount (Account) VALUES (@Account)", conn);
            cmd2.Parameters.AddWithValue("@Account", r.fAccounts);
            cmd2.ExecuteNonQuery();
        }
        conn.Close();
        }

0 个答案:

没有答案