Last post Feb 23, 2013 12:21 PM by Mac14
Feb 21, 2013 01:53 PM|Mac14|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 03:57 PM|Nasser Malik|LINK
You can get random word by tsql query
SELECT top 1 Word, Defination FROM MyDictionaryTable order by newid()
Feb 22, 2013 03:37 AM|Amy Peng - MSFT|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 06:46 AM|ashkc|LINK
FROM MyTable ORDER
Feb 23, 2013 12:21 PM|Mac14|LINK
Thank you everyone for your answers!
Amy, thanks for the code. It works fine!
Have a great day!