안녕하세요, 폼을 무작위로 데이터를로드 할 때 데이터베이스에서 검색하고 내 문제는 다시 데이터를 반복하지 않는 코드입니다 프로그램을 만드는 중입니다. 비주얼 베이직 2008 및 SQL 데이터베이스를 사용 메신저, 프로그래밍 언어 : 예를 들어 C#SQL 데이터베이스에서 무작위 데이터 가져 오기 반복 없음
:
Data in Database
Word_ID | Word
1 | eye
2 | cheese
3 | mouse
가 그런 부하를 형성
이 레이블에예를 들어 출력을 임의의 데이터 표시를 검색합니다 :
치즈
이제 치즈는 다음 무작위로 표시되지 않습니다
내 코드 : 당신이 문을 선택의 단지 where 절에 'A'와 WORD <> 'PreviousWord'으로로드 된 단어 등의 문제
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 (이미 발견 된 ID) '을 테스트해야합니다. –