Hi im creating a program where when the form loads random data will retrieve from the database and my problem is the code for not repeating the data again. im using vb 2008 and sql database, programming language : C#
for example:
Data in Database
Word_ID | Word
1 | eye
2 | cheese
3 | mouse
Then form loads it will retrieve random data and display in the label
example output:
cheese
so cheese now will not display on the next random
my code:
SqlConnection conn =
new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\sony\Documents\Visual Studio 2008\Projects\Hangman_Final\Hangman_Final\hangman_db.mdf;Integrated Security=True;User Instance=True");
conn.Open();
SqlCommand command = conn.CreateCommand();
command.CommandText = "SELECT TOP 1 Words from word order by NEWID()";
command.CommandType = CommandType.Text;
SqlDataReader reader = command.ExecuteReader();
// display the results
while (reader.Read())
{
string output = reader["Words"].ToString();
label5.Text = output;
}
// close the connection
reader.Close();
conn.Close();
WHERE word_id NOT IN (already found IDs)