Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2004, 05:35 PM
Registered User
 
Join Date: Mar 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default ongoing problem with random records....HELP!

hi,
for my coursework im using asp.net/vb.net. i am also using an oledbconnection. my problem is i need to generate 5 random records from a database when a start button is clicked, and display them on a page. each record must be different from the others. i think i need to use a loop but im not good enough in programming to kno how to do it. can anyone please help me out???? my code so far is displayed below which generates 1 records and displays it. but i need to to gerenate 5 different ones.

Sub Page_Load

if Session("userValid") = "Yes" then
Else
Response.redirect("Login.aspx")
End IF
Msg.Text =context.Session("Name")
Msg1.Text ="Please ensure you have read the instructions first!! and add all the other rules."

End Sub

Sub Log_Click(Src As Object, E As EventArgs)
Session.Abandon()
End Sub

Sub S_Click (Src As Object, E As EventArgs)

Dim i as integer
Randomize
i = CInt(Int((10 * Rnd()) + 1))

Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnection += "Data Source=C:*****"
Dim objConnection as New OledbConnection(strConnection)
Dim strSQL as string

objConnection.Open()

strSQL = "SELECT * FROM T1 WHERE QuestionNo = "& i &""

Dim objCOmmand as New OledbCommand(strSQL, objConnection)

objCommand = New OleDbCommand(strSQL, objConnection)

objCommand.ExecuteNonQuery()

objConnection.Close()

Dim objDataReader as OledbDataReader

objConnection.Open()

objDataReader = objCommand.ExecuteReader()
objDataReader.Read()

message.text = objDataReader("QuestionNo")
message1.text = objDataReader("Question")
message2.text = objDataReader("Answer1")
message3.text = objDataReader("Answer2")
message4.text = objDataReader("Answer3")
message5.text = objDataReader("Answer4")

objConnection.Close()

end sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">

<center><asp:Label id="Msg1" runat="server"></asp:Label>
</center>
<br />
<br />
<table id="Table1" width="500" align="center" border="1">
<tbody>
<tr>
<td>
Que: <asp:Label id="Message" runat="server"></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label id="Message1" runat="server"></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label id="Message2" runat="server"></asp:Label>
<br />
<asp:Label id="Message3" runat="server"></asp:Label>
<br />
<asp:Label id="Message4" runat="server"></asp:Label>
<br />
<asp:Label id="Message5" runat="server"></asp:Label>
<br />
</td>
</tr>
</tbody>
</table>
<br />
<br />
<table id="Table1" width="500" align="center" border="1">
<tbody>
<tr>
<td>
Que: </td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<br />
</td>
</tr>
</tbody>
</table>
<br />
<br />
<table id="Table1" width="500" align="center" border="1">
<tbody>
<tr>
<td>
Que: </td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<br />

</td>
</tr>
</tbody>
</table>
<br />
<br />
<table id="Table1" width="500" align="center" border="1">
<tbody>
<tr>
<td>
Que: </td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<br />
</td>
</tr>
</tbody>
</table>
<br />
<table id="Table1" width="500" align="center" border="1">
<tbody>
<tr>
<td>
Que: </td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</tbody>
</table>
<p>
<asp:button id="btnLogin" onclick="Log_Click" runat="Server" Text="Logout"></asp:button>
</p>
<br />
<asp:button id="Start" onclick="S_Click" runat="Server" Text="Start" </asp:button>
</p>
</form>
</body>
</html>







Similar Threads
Thread Thread Starter Forum Replies Last Post
csv with multiple records in random order biztalk xs2bharat Biztalk 0 May 2nd, 2007 07:09 AM
problem in updating records & finding records naveed77 VB Databases Basics 1 January 16th, 2007 12:12 PM
help with random records ps124 ASP.NET 1.0 and 1.1 Basics 0 March 14th, 2004 10:57 PM
Generating 5 unique random records from a database ps124 ASP.NET 1.0 and 1.1 Basics 2 March 8th, 2004 05:59 PM
random records from database HammR PHP Databases 1 December 11th, 2003 02:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.