Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 23, 2013 04:21 PM by Mac14
Feb 21, 2013 05:53 PM|LINK
I am trying to make a web application which shows you some words and their definitions. But I couldn't figure out how to get the words from the database? My database's name is "WordsDB". I have 2 columns. the one is "Word" and the other one is "Definition".
(Also there is an ID column). I want it to get the words randomly from the database when the applicaitons starts. And also there will be a button called "Another word". And this buttton will get another word randomly. Should I do its event same as the main
I am waiting for your answers,
Thank you for your help!
Feb 21, 2013 07:57 PM|LINK
You can get random word by tsql query
SELECT top 1 Word, Defination FROM MyDictionaryTable order by newid()
Feb 22, 2013 07:37 AM|LINK
Please try to refer to the following code:
protected void Button1_Click(object sender, EventArgs e)
SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=WordsDB;Integrated Security=True");
string ss = "select top 1 Word from testtable order by newid()";
SqlCommand cmd = new SqlCommand(ss, con);
Hope it can help.
Feb 22, 2013 10:46 AM|LINK
SELECT TOP 1 word FROM MyTable ORDER BY rand()
Feb 23, 2013 04:21 PM|LINK
Thank you everyone for your answers!
Amy, thanks for the code. It works fine!
Have a great day!