| | |
random selection of database entries
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
hello,
can anyone tell me how to randomly pick entries from a database using ASP.NET as front end and SQL SERVER as backend ?
i have written
select * from table order by rand();
but instead of picking entries randomly, it simply displays the entries in the same order as they are stored in the database..
thanks alot.
can anyone tell me how to randomly pick entries from a database using ASP.NET as front end and SQL SERVER as backend ?
i have written
select * from table order by rand();
but instead of picking entries randomly, it simply displays the entries in the same order as they are stored in the database..
thanks alot.
•
•
Join Date: Jun 2009
Posts: 439
Reputation:
Solved Threads: 82
Try this
This will pick 100 records randomly from a SQL Server 2005 table.
ASP.NET Syntax (Toggle Plain Text)
SELECT TOP 100 * FROM Your_Table_Name ORDER BY NEWID()
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
thankyou very much.. there seems to be a problem with SQL at my home so i was unable to try it yet..I'll try it in the uni the next time i go there.
another problem tht i m having is in this code..
this is the piece of code tht I have written for the sign in button. The problem here is tht whenever I input wrong entry it gives error in logging in.. Which is correct but when ever I enter an entry tht is present in the database it is stuck there and never goes to the next page and never shows the “logged in ” message. and sometimes it even shows the logged in message for wrong entries... i dont know how to handle it..i guess there is some mistake in the brackets..
can anyone help me??
thanks alot
another problem tht i m having is in this code..
ASP.NET Syntax (Toggle Plain Text)
protected void loginButton_Click1(object sender, EventArgs e) { DataSet temp = new DataSet(); temp = conn.retrieve("select * from candidate_info"); int i=0; int a = temp.Tables[0].Rows.Count; //object obj = new object(); object[] obj; while( i < a) { obj = temp.Tables[0].Rows[i].ItemArray; if (this.idTextBox.Text != obj[0].ToString() && this.passTextBox.Text != obj[1].ToString()) i++; } if (i == a) Response.Write("<script>alert('ERROR')</script>"); else Response.Write("<script>alert('Logged In')</script>"); }
this is the piece of code tht I have written for the sign in button. The problem here is tht whenever I input wrong entry it gives error in logging in.. Which is correct but when ever I enter an entry tht is present in the database it is stuck there and never goes to the next page and never shows the “logged in ” message. and sometimes it even shows the logged in message for wrong entries... i dont know how to handle it..i guess there is some mistake in the brackets..
can anyone help me??
thanks alot
Last edited by peter_budo; Jul 10th, 2009 at 6:24 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
I have tried this. please have a look at it and kindly let me know....
Errors are written within the code. and will you please explain how to access them using random class?
many thanks..
Errors are written within the code. and will you please explain how to access them using random class?
ASP.NET Syntax (Toggle Plain Text)
protected void loginButton_Click1(object sender, EventArgs e) { ArrayList arr = new ArrayList(); arr =conn.retrieve("select * from candidate_info"); /* Error:Cannot implicitly convert type 'System.Data.DataSet' to 'System.Collections.ArrayList' */ int i=0; int a = arr.Count; Random rand = new Random(); // where to use this random class. what will it do ??? while (i < a) { // rand = arr[0]; confused here ................ if (this.idTextBox.Text != obj[0].ToString() && this.passTextBox.Text != obj[1].ToString()) i++; } if(i == a) Response.Write("<script>alert('ERROR')</script>"); else Response.Write("<script>alert('Logged In')</script>"); }
many thanks..
Last edited by peter_budo; Jul 11th, 2009 at 2:38 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Try to modify your code segment in the following way. If matched then exit other wise after completion of all iteration its sure that no matched data found means error.
ASP.NET Syntax (Toggle Plain Text)
while (i < a) { // rand = arr[0]; confused here ................ // Use trim for fixed lenth db datattype if varchar then leave it if (this.idTextBox.Text == obj[0].ToString().Trim() && this.passTextBox.Text == obj[1].ToString().Trim()) { Response.Write("<script>alert('Logged In')</script>"); return; } i++; } Response.Write("<script>alert('ERROR')</script>");
Last edited by mail2saion; Jul 13th, 2009 at 1:15 am.
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
![]() |
Similar Threads
- Select random database value? (PHP)
- Display random image from database and... (PHP)
- How to choose random person on a database ( For a Game Show ) (PHP)
- Delphi - Database Entry Total (Pascal and Delphi)
- random selection with drag and drop label function( help needed!! ) (Visual Basic 4 / 5 / 6)
- ASP .NET Display Random records from the database (ASP.NET)
- Begginer here needs help (C)
- [Poll] Free ad impressions for your site (IT Professionals' Lounge)
- Checking for multiple database entries (PHP)
Other Threads in the ASP.NET Forum
- Previous Thread: How to bind data
- Next Thread: RadioButtonList within a GridView using the AJAX UpdatePanel
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net bc30451 beginner bottomasp.net box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownmenu dynamic edit embeddingactivexcontrol feedback fileuploader findcontrol flash flv forms gridview gudi homeedition iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings redirect relationaldatabases rotatepage save search security serializesmo.table sessionvariables silverlight smartcard sql ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment wizard xml





