Random Row Choice From Sql Database In Vb
Jan 6, 2012
I have created a small sql database using new data source. i have placed buttons to move to next,previous,first and last row but i am wondering if there is a way of making a button which would randomly pick a row with information from database or just make it randomize them before they are appearing on the screen.
At first i have tried creating random number generator and then joining it with the coulmns in the database. I failed in the end even though i thought it was going to work. Then i thought maybe i have to change the query as in, instead of "Select that and that and that from database" i thought i have to write "Select that and that from database sort by rand", i also saw that some people write limit 1 or more afterwards but i have no clue what it is and didnt use it. Anyhow i tried that query and it didnt work.
EDIT: I also thought about adding all questions into array, or use some sort of indexing, but i have to use database as the requirement.
Also if anyone would be willing to give me an advise of what is best book i could buy, which would cover databases in sql and some beginner/intermediate programming in visual basic.
View 1 Replies
ADVERTISEMENT
Jan 7, 2012
i have an sql database in my application and everything is working fine apart from one aspect.My random row picker code is located in one button on_click event. Is there a way of passing it over to other subs/on_click events?
[Code]...
View 1 Replies
Apr 21, 2010
Like how can i make it so it changes the text box to anyone of these words randomly
bob
somethinghere
somethinghere
somethinghere
[code]....
View 4 Replies
Nov 20, 2009
I've got a small pacman-like game where ghosts are running around a maze. At the moment, their movement is completely random. Each step, they determine which directions they can possibly move in (taking into account walls), and then they choose, randomly, one of those directions.Now, this works, but it's not very good. If a ghost is in a long corridor where he can only move up or down (or left/right), then he will usually not go anywhere, but just move up, down, up, down, down, up, up, down, up, etc. So, while it does move every step, in the long run it doesn't go anywhere.
View 7 Replies
Mar 12, 2010
I have four drop down lists here and I've assigned the datasource and displaymemberproperties so they are populated by a table. When I run the program and select a choice, all four of them get updated with the new choice.
View 3 Replies
Jan 14, 2010
I'm wanting to add a random number into a database but before I do this I want to check to see if I alreay have this number in there, How can I do a search to return a true or false I guess answer to if the value is in my access database?
View 22 Replies
Jan 24, 2011
i am serching for the random code for database the name of the table "q"
the fields
qu = label "the qustion"
an1 = button " answar 1 "
an2 = button " answar 2 "
an3 = button " answar 3 "
an4 = button " answar 4 "
[Code]...
View 1 Replies
Jun 3, 2009
As in today i click on the button it will display the item when i hit again the button it will still display the same item and last for the whole. On the second day, i hit the button again it will display other items and last for thewhole day again.
[Code]...
View 1 Replies
Feb 15, 2012
I just want to select 1 random record from my database for example in my table1 i have a,b,c,d,e,f,g then everytime i click the button in my program it will output randomly between a to g then i can add another record from my database and if I make it a to x it will randomly choose between a to x, the random doesnt have any conditions.
Right now i've found some codes that will be very useful but i cant modify it so it will be connected to my database.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DT1 As New DataTable
DT1.Columns.Add("SN1")
DT1.Columns.Add("NAME1")
[Code]...
View 2 Replies
Jun 22, 2010
I am trying to generate random images from access database using hashset as it is said to be unique and there won't be any repeated images appearing. But, it doesn't seem to work.
How can i get it to work? By the way, i am very new to the concept of hashset.
Private Function GetImageFromByteArray(ByVal picData As Byte()) As Image
If picData Is Nothing Then
Return Nothing
End If
' is this is an embedded object?
Dim bmData As Integer = If((picData(0) = 21 AndAlso picData(1) = 28), 78, 0)
' load the picture
Dim img As Image = Nothing
Try
Dim ms As New MemoryStream(picData, bmData, picData.Length - bmData)
img = Image.FromStream(ms)
Catch
End Try
' return what we got
Return img
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Panel1.Visible = False
Panel2.Hide()
Dim conn As New OleDbConnection
Dim DA As OleDbDataAdapter
Dim DS As New DataSet
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;User Id=admin;Password=;"
DA = New OleDbDataAdapter("Select Empty, EmptyName, Target, TargetName from PicturesDisplayed", conn)
DA.Fill(DS)
Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Dim oledbconnection As OleDbConnection
oledbconnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsAdministratorDesktopdb1.mdb;Jet OLEDB:System Database=system.mdw;")
oledbconnection.Open()
Dim command As OleDbCommand
command = New OleDbCommand("select count (*) from PicturesDisplayed", oledbconnection)
Dim count As Integer
count = command.ExecuteScalar()
oledbconnection.Close()
Dim randomImage As New HashSet(Of Integer)
' Create a integer and new Random object
Dim intPic As Integer
Dim rand As New Random
'Pick a random number between 0 and the number of images in database
intPic = rand.Next(0, count)
randomImage.Add(intPic)
PictureBox1.Height = 256
PictureBox1.Width = 256
PictureBox2.Height = 256
PictureBox2.Width = 256
Dim pic1x As Integer = _
(Me.ClientSize.Width - PictureBox1.Width) 2
Dim pic1y As Integer = _
(Me.ClientSize.Height - PictureBox1.Height) 2
PictureBox1.Location = New Point(pic1x, pic1y)
Dim pic2x As Integer = _
(Me.ClientSize.Width - PictureBox2.Width) 2
Dim pic2y As Integer = _
(Me.ClientSize.Height - PictureBox2.Height) 2
PictureBox2.Location = New Point(pic2x, pic2y)
' Now set the picturebox image equal to the image chosen from the array randomly using the random
PictureBox1.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(0))
PictureBox1.Visible = True
PictureBox2.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(2))
PictureBox2.Visible = False
If (randomImage.Count = count) Then
Me.Close()
End If
End Sub
View 1 Replies
Mar 3, 2008
I'm wanting to alter a column in an acces database, to a Random AutoNumber I know how to do it for incremental e.g."ALTER TABLE MyField Counter(1,1)"but how do you do it for a Random Autonumber??
View 10 Replies
Oct 21, 2011
So in my program I have a database where I send info such as passwords, is there any way to (in an easy way) encrypt the password before sending it so instead of sending "mypassword" to the database I send a random collection of letters and numbers like "shH3n2ja"? I only need two functions, encryptPassword, decryptPassword.
View 7 Replies
Feb 29, 2012
i have this database format in SQL:
ID name add num
1 fel mn 201
2 john kaye 23
3 Kate mani 25
I used databinding to call the values on (SQL) to textboxes in visual studio 2010 and i have this code in NEXT command:
Inter is the name of the databinding
With inter1
If .Position = .Count - 1 Then
[code]....
The code above display the information not on Random. How can i display those information in Random mode? And i need a msgbox when all the data has been already seen by the user. I mean no redundant data will be seen by the user upon random mode has been done.
View 8 Replies
Apr 8, 2009
I am about to start developing my second application in VB2008. The need is that it has to run on a network enviorment, probably under windows nt, the database has to be on the server so everybody uses the same data. The database is suppose to contain a lot of data on many tables, whatīs the ebst way to go? Access, SQL, foxpro dbf? Also what kind of project am I suppose to start? a windows app? or some kind of .net app.? I am sorry if I am saying dumb stuff itīs just that I am a rookie. Have in mind that after I build the application, many users have to have access to it from different computers and I also want the database to be availbale for a future website with forms and queries and stuff taken from the same database, is ASP the best choice for that purppose?
View 6 Replies
May 20, 2009
I'm developing a form that displays conference attendee data.I have a panel control on this form and would like to put a series of buttons at the bottom of this form that will open other forms in the panel. So for example, there would be a button to open the Address form, another button to open the Email form, and so on.There will be 10 buttons total. I have the Address and Email forms set up so far and it seems to work pretty slick.
Before I go any further, is this the best way to do this? FWIW, all forms will have a datarepeater control on them since there can be multiple addresses per attendee, multiple emails, etc.
View 9 Replies
Feb 17, 2011
I have a combo box which is set up with the follow properties and is populated with data and one blank row.
DropDownStyle = DropDownList
sometimes i get a message box even thought something is selected, what could be wrong?[code]...
View 4 Replies
Feb 17, 2009
I made a combo box and i need to know how to set one variable for each choice in the combo box. for example, my choices are poor, average, good, and superior. I want to set the "poor" variable as the poor option in the combo box and the "average" variable as the average option in the combo box and so on and so forth.
View 3 Replies
Dec 24, 2009
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If CheckBox1.Checked = True Then
[code].....
View 4 Replies
May 26, 2011
I've read numerous posts and threads about random number generation, but I havent' run across this.If I generate a bunch of random numbers, the results are radically different if I create a new Random generator for each number than if I use on Random generator for all the numbers. The results are much more consistent and evenly distributed if I use the same Random generator.I would have thought the opposite,because creating a new Random generator each time should reduce the number of random repetitions, if a different time slice is used to create the random number.[code]......
View 9 Replies
Apr 4, 2010
The class Random is out right defective. It always produces the same random numbers in the same sequence. Things I have tried so far is every kind of seed you can think of as well as Randomize. The result is that I always get the same random numbers in exactly the same sequence.
View 4 Replies
Nov 26, 2011
I am practicing using the drawing commands, and have gotten a grass background and black happy face that moves around the background.It's a 10x10 grid of 50 pixels.I want (at the moment, when i press enter) it to generate a random number of trees (15 ~ 25) at random locations on the background. The program doesn't freak out about anything, and the variables seem to be right (using stop commands) but it's not drawing anything. Here is the code for the "GenerateTrees" command I have for when I press enter.
Private Sub GenerateTrees()
NumberOfTrees = Int(Rnd() * 10) + 15
For i = 0 To NumberOfTrees - 1
bmap.MakeTransparent(Color.Fuchsia)
[code].....
View 4 Replies
Jun 1, 2012
Has anyone ever set up a Multiple choice test before?
View 4 Replies
Feb 24, 2009
I'm not great with VB and I'm having some trouble with my University assignment at the moment.I'm trying to code a multiple choice program with several forms with different questions and then a scoring form
I'm not sure how to tell VB what the correct answer should be and how to display the scores in another form, the answers need to show how many correct in each section out of how many the user attemped to answer, so they can check scores before completing all the questions.
View 5 Replies
May 13, 2012
I'm currently quite new to VB and am trying to create a multiple choice questionnaire for work. This is a depression survey in which there are 23 groups of statements with 4 options per group. Every time a patient clicks an option, the next set of 4 questions comes up on the screen.
I'm trying to convert the old VB4 code into the new VB 2010 code. Before we were using a control array and the code looks a little something like this[code]...
View 2 Replies
Jan 12, 2010
sample_form.rtf (1.48MB). Number of downloads: 36. I have a working form to give specific choices to the user and retrieve the user's choice. (See code below and attached image in WordPad file.) I know I can use a global ("Public") variable to pass the text of the three choices from the calling form to the called form, but is there a way to pass these from one form to the other exclusively? Of course, my main objective is to have as little memory being used as possible. I would like to make the form in my example (frmDialogChoice) a generic form that can display any set of three choices.
code within calling form:
Dim intSwitchToMake As Integer
Dim insFrmDialogChoice As New frmDialogChoice
insFrmDialogChoice.ShowDialog()
[CODE]....
View 5 Replies
Sep 10, 2010
No doubt a simple question, but I'm a beginner (I learnt GW BritingASIC in 3 months long ago - but after 6 months grappling with vb 2008 I am still bewidered).
I have written a program that asks the user at run time to choose 1 of 40 buttons. These are themselves defined at run time. Whichever button is chosen the same algoritm will run (using different data). Question: To save writing the same Button_Click routine 40 times, what code should I write - and where in the program - to detect which of the 40 the user has chosen?
View 2 Replies
Dec 20, 2010
How do I list the column name as a choice in a combo box?
View 2 Replies
Jan 17, 2012
I have a list of ID's which each ID represent an item in a game. For example, ID "4022" represents "Basic Wand" (Example). I have a list of ID's, now what I want to do is: Have a listview which has each line for an item. When you click on any item, the PictureBox will change according to your ID choice.
How can I use these ID's and store them for each item (text)?
View 2 Replies
May 10, 2009
I need a multiple choice quiz but I've ran into some problems. So far i have 5 arrays: one for the questions and four for the answers. The question is displayed in a label and the answers on radio buttons. Problem one: I am using a random number generator to pull them but this allows them to be reused. How do I stop repeats. Problem two, my grading isn't always working.
View 3 Replies
Apr 10, 2009
I need my program to let the user choose a text file by browsing the computer then the file path of the file needs to be set as the New StreamReader path so that the computer can open the file.
[Code]...
View 1 Replies