realityfusion
New member
- Joined
- Jan 18, 2010
- Messages
- 3
- Programming Experience
- 1-3
Hello All!
I would like to take a moment to thank the members of this community you have been a great help so far on my VB questions. I very much appreciate it.
I am a recovering MS ACCESS user, and I am trying to learn VB. So many of the things I am familair with seem greek in Visual Studio
Here is my Current Problem
I want to loop through a database in VB 2008 ans when I find a particular value add 1 to a counter. here is the code in action working in ACCESS and vba
Here is the form that I will be using this function on
The Table is Called 'Number' the column I want is called 'SpinNumber'
I am able to connect to the database and insert values no problem.
My problem is I have no idea how to retrieve a single value from the database
I can retrieve a grid of data but not just a single peice
as in the previous example I just want to go to the end of the database so I can see the most recent numbers and loop backwards from there and then see if that value equals a certain amount. as they do I want to count until it no longer see them.
I hope I made what it is I am wanting to do clear. and I appreciate any help I can get.
Thanks,
Chase
I would like to take a moment to thank the members of this community you have been a great help so far on my VB questions. I very much appreciate it.
I am a recovering MS ACCESS user, and I am trying to learn VB. So many of the things I am familair with seem greek in Visual Studio
Here is my Current Problem
I want to loop through a database in VB 2008 ans when I find a particular value add 1 to a counter. here is the code in action working in ACCESS and vba
VB.NET:
Set rstNumbers = db.OpenRecordset("numbers", dbOpenDynaset, dbSeeChanges)
'Row Low
'Check that there are records
If rstNumbers.EOF Or rstNumbers.BOF = True Then GoTo jump_out
'move to the end of the table
rstNumbers.MoveLast
'if the last entry is "1" add once to the lowrow text box
If rstNumbers![Row] = "1" Then
[RowLow] = 1
GoTo Row_Mid
End If
Do While Counter = 0
'if the value of the row is one increase the counter and goto the next step
If rstNumbers![Row] = "1" Then
Counter = Counter + 1
GoTo Row_Mid
Else
'until the value equals "1" add 1 to the low row counter
[RowLow] = [RowLow] + 1
End If
'goto the previous tow
rstNumbers.MovePrevious
Loop
Here is the form that I will be using this function on
The Table is Called 'Number' the column I want is called 'SpinNumber'
I am able to connect to the database and insert values no problem.
My problem is I have no idea how to retrieve a single value from the database
I can retrieve a grid of data but not just a single peice
as in the previous example I just want to go to the end of the database so I can see the most recent numbers and loop backwards from there and then see if that value equals a certain amount. as they do I want to count until it no longer see them.
I hope I made what it is I am wanting to do clear. and I appreciate any help I can get.
Thanks,
Chase
VB.NET:
Imports System.Data.SqlServerCe
Imports System.Data.Sql
Public Class Form1
Dim RedTextHolder
Dim BlackTextHolder
Dim NumberClickHolder
Dim my1stPosition
Dim Def As New definitions
Public Sub UserData()
Dim con As SqlCeConnection = New SqlCeConnection("Data Source=Database1.sdf")
Dim cmd As SqlCeCommand
Dim myDA As SqlCeDataAdapter
Dim myDataSet As DataSet
con.Open()
cmd = New SqlCeCommand("Select SpinNumber From Number", con)
myDA = New SqlCeDataAdapter(cmd)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "Number")
DataGridView1.DataSource = myDataSet.Tables("Number").DefaultView
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
UserData()
End Sub
Private Sub Numbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
Button0.Click, Button1.Click, Button2.Click, Button3.Click, Button4.Click, _
Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, _
Button10.Click, Button11.Click, Button12.Click, Button13.Click, Button14.Click, _
Button15.Click, Button16.Click, Button17.Click, Button18.Click, Button19.Click, _
Button20.Click, Button21.Click, Button22.Click, Button23.Click, Button24.Click, _
Button25.Click, Button26.Click, Button27.Click, Button28.Click, Button29.Click, _
Button30.Click, Button31.Click, Button32.Click, Button33.Click, Button34.Click, _
Button35.Click, Button36.Click
If Def.RedBlack(sender.text) = "Red" Then
RedTextHolder = RedListBox.Text
RedListBox.Text = sender.text & vbCrLf + RedTextHolder
BlackTextHolder = BlackListBox.Text
BlackListBox.Text = vbCrLf + BlackTextHolder
Else
BlackTextHolder = BlackListBox.Text
BlackListBox.Text = sender.text & vbCrLf + BlackTextHolder
RedTextHolder = RedListBox.Text
RedListBox.Text = vbCrLf + RedTextHolder
End If
Dim con As SqlCeConnection = New SqlCeConnection("Data Source=Database1.sdf")
Dim cmd As SqlCeCommand
con.Open()
cmd = New SqlCeCommand("INSERT INTO Number(SpinNumber)VALUES('" & sender.text & "')", con)
cmd.ExecuteNonQuery()
UserData()
End Sub
End Class