Note that there are some explanatory texts on larger screens.

plurals
  1. POcomparing values using C# and inserting row IF true
    text
    copied!<p>I have the follow code which will randomly assign 6 numbers to my array.</p> <pre><code>public void LottoWinners(object sender, EventArgs e) { Dictionary&lt;int, int&gt; number = new Dictionary&lt;int, int&gt;(); Random generator = new Random(); while (number.Count &lt; 6) { number[generator.Next(1, 49)] = 1; } string[] lotto = number.Keys.OrderBy(n =&gt; n).Select(s =&gt; s.ToString()).ToArray(); //write some logic to find out who has 3 match numbers //and assign there ticket to the winners table tblWinners } </code></pre> <p>I need to then compare the values in the array with the values in the tblTickets table to see who the winners are. HOWEVER i need to break down the winners:</p> <p>So if they have 3 matching numbers then insert there ticketID into the tblWinners table.</p> <p>I was thinking about writing a case statement but how do check for equality?</p> <p>The problem is i hold my values in the table like this:</p> <pre><code>tblLotto(val0,val1,val2,val3,val4,val5) </code></pre> <p>So i need to search my table using some sort of logic....</p> <p>My players class looks like this:</p> <p>public class players { public void LottoDraw(object sender, EventArgs e) { var connectionstring = "Server=C;Database=lotto;User Id=lottoadmin;Password=password;";</p> <pre><code> 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); } } } } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload