Hi all
I have setup a database with 15 bingo numbers per row (see image), I'm trying to search for the first ticket number which is in a column is called number and then retrieve bingo numbers and update the printed column from no to yes to stop it being read again.
the problem that I'm having is if there is more than one computer connected to the database, some times the same ticket number is read on both machines and prints the same numbers and ticket number. Which I don't want to happen. works fine if only one
I have tried us the XLOCK, ROWLOCK, UPDLOCK, HOLDLOCK without any luck
so hopefully someone could suggest a better way of doing this
here my code
OpenSQLdatabase() '---this opens the database
Dim myCommand As SqlCommand
Dim dr As SqlDataReader
Try
myCommand = New SqlCommand("SELECT * FROM Bingo WHERE PRINTED='no'", conn) '--- this will get the first ticket number (ORDER DESC for last number)
'myCommand = New SqlCommand("SELECT * FROM Bingo WITH (UPDLOCK, HOLDLOCK) WHERE PRINTED='no'", conn)
'executing the command and assigning it to connection
dr = myCommand.ExecuteReader(CommandBehavior.SingleRow) '-- this has been changed for single row read
'dr = myCommand.ExecuteReader() '-- this will search all rows
While dr.Read()
'reading from the datareader
BingoNumbers(0) = dr(0)
BingoNumbers(1) = dr(1)
BingoNumbers(2) = dr(2)
BingoNumbers(3) = dr(3)
BingoNumbers(4) = dr(4)
BingoNumbers(5) = dr(5)
BingoNumbers(6) = dr(6)
BingoNumbers(7) = dr(7)
BingoNumbers(8) = dr(8)
BingoNumbers(9) = dr(9)
BingoNumbers(10) = dr(10)
BingoNumbers(11) = dr(11)
BingoNumbers(12) = dr(12)
BingoNumbers(13) = dr(13)
BingoNumbers(14) = dr(14)
intTicketNumer = dr(15) '-- used for printing ticket number
End While
dr.Close()
conn.Close()
'--- now update as printed to stop it being read again
OpenSQLdatabase()
sql = "UPDATE Bingo SET Printed='yes' WHERE number=@number"
cmd = New SqlCommand(sql, conn)
cmd.Parameters.AddWithValue("@number", intTicketNumer)
ExecuteNonQueryMethod()
PrintBingoTicket()
thanks in advance
I have setup a database with 15 bingo numbers per row (see image), I'm trying to search for the first ticket number which is in a column is called number and then retrieve bingo numbers and update the printed column from no to yes to stop it being read again.
the problem that I'm having is if there is more than one computer connected to the database, some times the same ticket number is read on both machines and prints the same numbers and ticket number. Which I don't want to happen. works fine if only one
I have tried us the XLOCK, ROWLOCK, UPDLOCK, HOLDLOCK without any luck
so hopefully someone could suggest a better way of doing this
here my code
OpenSQLdatabase() '---this opens the database
Dim myCommand As SqlCommand
Dim dr As SqlDataReader
Try
myCommand = New SqlCommand("SELECT * FROM Bingo WHERE PRINTED='no'", conn) '--- this will get the first ticket number (ORDER DESC for last number)
'myCommand = New SqlCommand("SELECT * FROM Bingo WITH (UPDLOCK, HOLDLOCK) WHERE PRINTED='no'", conn)
'executing the command and assigning it to connection
dr = myCommand.ExecuteReader(CommandBehavior.SingleRow) '-- this has been changed for single row read
'dr = myCommand.ExecuteReader() '-- this will search all rows
While dr.Read()
'reading from the datareader
BingoNumbers(0) = dr(0)
BingoNumbers(1) = dr(1)
BingoNumbers(2) = dr(2)
BingoNumbers(3) = dr(3)
BingoNumbers(4) = dr(4)
BingoNumbers(5) = dr(5)
BingoNumbers(6) = dr(6)
BingoNumbers(7) = dr(7)
BingoNumbers(8) = dr(8)
BingoNumbers(9) = dr(9)
BingoNumbers(10) = dr(10)
BingoNumbers(11) = dr(11)
BingoNumbers(12) = dr(12)
BingoNumbers(13) = dr(13)
BingoNumbers(14) = dr(14)
intTicketNumer = dr(15) '-- used for printing ticket number
End While
dr.Close()
conn.Close()
'--- now update as printed to stop it being read again
OpenSQLdatabase()
sql = "UPDATE Bingo SET Printed='yes' WHERE number=@number"
cmd = New SqlCommand(sql, conn)
cmd.Parameters.AddWithValue("@number", intTicketNumer)
ExecuteNonQueryMethod()
PrintBingoTicket()
thanks in advance