我有以下代码,它将随机为我的数组分配 6 个数字。
public void LottoWinners(object sender, EventArgs e)
{
Dictionary<int, int> number = new Dictionary<int, int>();
Random generator = new Random();
while (number.Count < 6)
{
number[generator.Next(1, 49)] = 1;
}
string[] lotto = number.Keys.OrderBy(n => n).Select(s => s.ToString()).ToArray();
//write some logic to find out who has 3 match numbers
//and assign there ticket to the winners table tblWinners
}
然后,我需要将数组中的值与 tblTickets 表中的值进行比较,以查看获胜者是谁。但是我需要分解获胜者:
因此,如果他们有 3 个匹配的号码,则将 ticketID 插入到 tblWinners 表中。
我正在考虑写一个案例陈述,但如何检查平等?
问题是我在表中保存我的值,如下所示:
tblLotto(val0,val1,val2,val3,val4,val5)
所以我需要使用某种逻辑搜索我的表....
我的玩家类如下所示:
公共类玩家 { public void LottoDraw(object sender, EventArgs e) { var connectionstring = "Server=C;Database=lotto;User Id=lottoadmin;Password=password;";
using (var con = new SqlConnection(connectionstring)) // Create connection with automatic disposal
{
con.Open();
// Create new DataTable
DataTable player = new DataTable();
{
// Create new DataAdapter
using (SqlDataAdapter a = new SqlDataAdapter("SELECT TOP 1 LOTTOID, VAL0, VAL1, VAL2, VAL3, VAL4, VAL5 FROM tblLotto ORDER BY NEWID()", con))
{
// Use DataAdapter to fill DataTable
a.Fill(player);
}
}
}
}
}
}