我的方法无效,我在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();
}