Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 28th, 2008, 03:38 PM
Newbie
 
Join Date: Aug 2008
Posts: 2
Default Stepping through a record set

Hi,
I'm working on an applet that allows a user to step through the results of a query and edit the information.

I have it so that you can click one button to get the image and another to update the record, however, I cannot figure out how to keep the recordset open in a way so that when I click the update button it moves to the next entry.

Any help or insight would be greatly appreciated
Thanks,
Steve

The current code looks like this:
Private Sub GetImageButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetImageButton.Click

FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
Do Until LineInput(1) = "**ADImageLocation**"
Loop
Dim ADImageLocation As String = LineInput(1)
FileClose(1)

FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
Do Until LineInput(1) = "**ADImageConnection**"
Loop
Dim ADImageConnection As String = LineInput(1)
FileClose(1)
Dim Area As String
Dim Controller As String
Controller = "No"
Area = AreaBox.Text
CN = New ADODB.Connection
CN.Open(ADImageConnection)
RS = New Global.ADODB.Recordset

Try
RS.Open("SELECT * FROM ImageData WHERE Area = '" & Area & "' and Control = '" & Controller & "' ", CN)

RS.MoveNext()

DateBox.Text = RS.Fields("Date").Value
InitialsBox.Text = RS.Fields("Initials").Value
PartIDBox.Text = RS.Fields("PartID").Value
LotNumberBox.Text = RS.Fields("LotNumber").Value
ProcessBox.Text = RS.Fields("Process").Value
AreaBox.Text = RS.Fields("Area").Value
StageBox.Text = RS.Fields("Stage").Value
UniqueIDBox.Text = RS.Fields("DateTimeIdentifier_UniqueSystemID").Val ue
CommentsBox.Text = RS.Fields("Comments").Value
If RS.Fields("Control").Value = "YES" Then
Thecontrolbox.Text = "Controlled"
Else
Thecontrolbox.Text = "Uncontrolled"
End If

Catch
MsgBox("Record Not Found")

End Try

'Get Next rs

UniqueID = UniqueIDBox.Text
Try
ImageDisplay.Image = System.Drawing.Image.FromFile(ADImageLocation & UniqueID & ".jpeg")
ImageDisplay.Visible = True
ImageDisplay.SizeMode = PictureBoxSizeMode.StretchImage
Catch
MsgBox("Image Not Found")
End Try

End Sub


Private Sub UpdateRecordButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateRecordButton.Click
Dim Area As String
Dim Controller As String
Controller = "No"
Area = AreaBox.Text
'get connection strings from setup file
FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
Do Until LineInput(1) = "**ADImageLocation**"
Loop
Dim ADImageLocation As String = LineInput(1)
FileClose(1)

FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
Do Until LineInput(1) = "**ADImageConnection**"
Loop
Dim ADImageConnection As String = LineInput(1)
FileClose(1)

UniqueID = UniqueIDBox.Text

CN = New ADODB.Connection
CN.Open(ADImageConnection)
RS = New ADODB.Recordset
RS.Open("DELETE FROM ImageData WHERE DateTimeIdentifier_UniqueSystemID = '" & UniqueID & "' ", CN)
' CN.Close()
Try
CN = New ADODB.Connection
CN.Open(ADImageConnection)
RS = New ADODB.Recordset
RS.Open("select * from ImageData ", CN, 1, 2)
RS.AddNew()
RS.Fields("DateTimeIdentifier_UniqueSystemID").Val ue() = UniqueID
RS.Fields("Date").Value = DateBox.Text
RS.Fields("Initials").Value = InitialsBox.Text
RS.Fields("PartID").Value = PartIDBox.Text
RS.Fields("LotNumber").Value = LotNumberBox.Text
RS.Fields("Process").Value = ProcessBox.Text
If Thecontrolbox.Text = "Controlled" Then
RS.Fields("Control").Value = "YES"
ElseIf Thecontrolbox.Text = "Uncontrolled" Then
RS.Fields("Control").Value = "NO"
End If

RS.Fields("Area").Value = AreaBox.Text
RS.Fields("Stage").Value = StageBox.Text
RS.Fields("Comments").Value = CommentsBox.Text
RS.Fields("ImageName").Value = UniqueID & ".Jpeg"
RS.Fields("Keywords").Value = UniqueIDBox.Text & " , " & DateBox.Text & " , " & InitialsBox.Text & " , " & PartIDBox.Text & " , " & LotNumberBox.Text & " , " & ProcessBox.Text & Thecontrolbox.Text & " , " & AreaBox.Text & " , " & StageBox.Text & " , " & CommentsBox.Text
RS.Update()
CN.Close()
'if the emergency form isnt open yet, open it!
Catch
MsgBox("There has been a connection error. Please contact your network administrator and try again later.")
End Try
If CurrentErrorNumber = 1 Then
Dim StartEmergency As New Emergency
StartEmergency.Show()
ADILogo.Image = System.Drawing.Image.FromFile("C:\Program Files\ADImage\networkdown.bmp")
End If ' end the 'start emergency if its not open

UniqueIDBox.Text = ""
DateBox.Text = ""
InitialsBox.Text = ""
PartIDBox.Text = ""
LotNumberBox.Text = ""
ProcessBox.Text = ""
Thecontrolbox.Text = Nothing
'AreaBox.Text = ""
StageBox.Text = ""
CommentsBox.Text = ""
ImageDisplay.Image.Dispose()
ImageDisplay.Image = Nothing

'Indicating to the user that the image has been updated.
MsgBox("Image data has been updated", MsgBoxStyle.OkOnly, "Image Data Updated")

End Sub
Reply
  #2  
Old August 28th, 2008, 06:39 PM
Newbie
 
Join Date: Aug 2008
Posts: 2
Default

Hey,

I believe I figured this one out. Just needed to create a temporary table.

Expand|Select|Wrap|Line Numbers
  1. Private Sub GetImageButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetImageButton.Click
  2.  
  3.         FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
  4.         Do Until LineInput(1) = "**ADImageLocation**"
  5.         Loop
  6.         Dim ADImageLocation As String = LineInput(1)
  7.         FileClose(1)
  8.  
  9.         FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
  10.         Do Until LineInput(1) = "**ADImageConnection**"
  11.         Loop
  12.         Dim ADImageConnection As String = LineInput(1)
  13.         FileClose(1)
  14.         Dim Area As String
  15.         Dim Controller As String
  16.         Controller = "No"
  17.         Area = AreaBox.Text
  18.         CN = New ADODB.Connection
  19.         CN.Open(ADImageConnection)
  20.         temp = New Global.ADODB.Recordset
  21.         Try
  22.             temp.Open("SELECT * FROM ImageData WHERE Area = '" & Area & "' and Control = '" & Controller & "' ", CN)
  23.  
  24.             DateBox.Text = temp.Fields("Date").Value
  25.             InitialsBox.Text = temp.Fields("Initials").Value
  26.             PartIDBox.Text = temp.Fields("PartID").Value
  27.             LotNumberBox.Text = temp.Fields("LotNumber").Value
  28.             ProcessBox.Text = temp.Fields("Process").Value
  29.             AreaBox.Text = temp.Fields("Area").Value
  30.             StageBox.Text = temp.Fields("Stage").Value
  31.             UniqueIDBox.Text = temp.Fields("DateTimeIdentifier_UniqueSystemID").Value
  32.             CommentsBox.Text = temp.Fields("Comments").Value
  33.             If temp.Fields("Control").Value = "YES" Then
  34.                 Thecontrolbox.Text = "Controlled"
  35.             Else
  36.                 Thecontrolbox.Text = "Uncontrolled"
  37.             End If
  38.  
  39.         Catch
  40.             MsgBox("Record Not Found")
  41.  
  42.         End Try
  43.  
  44.         'Get Next rs
  45.  
  46.         UniqueID = UniqueIDBox.Text
  47.         Try
  48.             ImageDisplay.Image = System.Drawing.Image.FromFile(ADImageLocation & UniqueID & ".jpeg")
  49.             ImageDisplay.Visible = True
  50.             ImageDisplay.SizeMode = PictureBoxSizeMode.StretchImage
  51.         Catch
  52.             MsgBox("Image Not Found")
  53.         End Try
  54.  
  55.     End Sub
  56.  
  57. Private Sub UpdateRecordButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateRecordButton.Click
  58.         Dim Area As String
  59.         Dim Controller As String
  60.         Controller = "No"
  61.         Area = AreaBox.Text
  62.         'get connection strings from setup file
  63.         FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
  64.         Do Until LineInput(1) = "**ADImageLocation**"
  65.         Loop
  66.         Dim ADImageLocation As String = LineInput(1)
  67.         FileClose(1)
  68.  
  69.         FileOpen(1, "C:\Program Files\ADImage\ADImageSetup.txt", OpenMode.Input)
  70.         Do Until LineInput(1) = "**ADImageConnection**"
  71.         Loop
  72.         Dim ADImageConnection As String = LineInput(1)
  73.         FileClose(1)
  74.  
  75.         UniqueID = UniqueIDBox.Text
  76.  
  77.         'Check to see if record is in the database - this way it won't crash on blank or broken entry.
  78.         Dim EntryExists As Boolean = True
  79.         Try
  80.             CN = New ADODB.Connection
  81.             CN.Open(ADImageConnection)
  82.             RS = New ADODB.Recordset
  83.             RS.Open("SELECT * FROM ImageData WHERE DateTimeIdentifier_UniqueSystemID = '" & UniqueID & "' ", CN)
  84.         Catch
  85.             'tell user record isn't in database, turn off errorvariable
  86.             MsgBox("Record not found")
  87.             EntryExists = False
  88.         End Try
  89.         CN.Close()
  90.  
  91.         'if it was there, delete it from the database and write a new entry with the new info.  
  92.         'If EntryExists Then
  93.  
  94.         CN = New ADODB.Connection
  95.         CN.Open(ADImageConnection)
  96.         RS = New ADODB.Recordset
  97.         RS.Open("DELETE FROM ImageData WHERE DateTimeIdentifier_UniqueSystemID = '" & UniqueID & "' ", CN)
  98.         CN.Close()
  99.         Try
  100.             CN = New ADODB.Connection
  101.             CN.Open(ADImageConnection)
  102.             RS = New ADODB.Recordset
  103.             RS.Open("select * from ImageData ", CN, 1, 2)
  104.             RS.AddNew()
  105.             RS.Fields("DateTimeIdentifier_UniqueSystemID").Value() = UniqueID
  106.             RS.Fields("Date").Value = DateBox.Text
  107.             RS.Fields("Initials").Value = InitialsBox.Text
  108.             RS.Fields("PartID").Value = PartIDBox.Text
  109.             RS.Fields("LotNumber").Value = LotNumberBox.Text
  110.             RS.Fields("Process").Value = ProcessBox.Text
  111.             If Thecontrolbox.Text = "Controlled" Then
  112.                 RS.Fields("Control").Value = "YES"
  113.             ElseIf Thecontrolbox.Text = "Uncontrolled" Then
  114.                 RS.Fields("Control").Value = "NO"
  115.             End If
  116.  
  117.             RS.Fields("Area").Value = AreaBox.Text
  118.             RS.Fields("Stage").Value = StageBox.Text
  119.             RS.Fields("Comments").Value = CommentsBox.Text
  120.             RS.Fields("ImageName").Value = UniqueID & ".Jpeg"
  121.             RS.Fields("Keywords").Value = UniqueIDBox.Text & " , " & DateBox.Text & " , " & InitialsBox.Text & " , " & PartIDBox.Text & " , " & LotNumberBox.Text & " , " & ProcessBox.Text & Thecontrolbox.Text & " , " & AreaBox.Text & " , " & StageBox.Text & " , " & CommentsBox.Text
  122.             RS.Update()
  123.             CN.Close()
  124.             'if the emergency form isnt open yet, open it!
  125.         Catch
  126.             MsgBox("There has been a connection error.  Please contact your network administrator and try again later.")
  127.         End Try
  128.         If CurrentErrorNumber = 1 Then
  129.             Dim StartEmergency As New Emergency
  130.             StartEmergency.Show()
  131.             ADILogo.Image = System.Drawing.Image.FromFile("C:\Program Files\ADImage\networkdown.bmp")
  132.         End If ' end the 'start emergency if its not open
  133.  
  134.         UniqueIDBox.Text = ""
  135.         DateBox.Text = ""
  136.         InitialsBox.Text = ""
  137.         PartIDBox.Text = ""
  138.         LotNumberBox.Text = ""
  139.         ProcessBox.Text = ""
  140.         Thecontrolbox.Text = Nothing
  141.         'AreaBox.Text = ""
  142.         StageBox.Text = ""
  143.         CommentsBox.Text = ""
  144.         ImageDisplay.Image.Dispose()
  145.         ImageDisplay.Image = Nothing
  146.  
  147.         'Indicating to the user that the image has been updated.
  148.         MsgBox("Image data has been updated", MsgBoxStyle.OkOnly, "Image Data Updated")
  149.  
  150.         temp.MoveNext()
  151.  
  152.         DateBox.Text = temp.Fields("Date").Value
  153.         InitialsBox.Text = temp.Fields("Initials").Value
  154.         PartIDBox.Text = temp.Fields("PartID").Value
  155.         LotNumberBox.Text = temp.Fields("LotNumber").Value
  156.         ProcessBox.Text = temp.Fields("Process").Value
  157.         AreaBox.Text = temp.Fields("Area").Value
  158.         StageBox.Text = temp.Fields("Stage").Value
  159.         UniqueIDBox.Text = temp.Fields("DateTimeIdentifier_UniqueSystemID").Value
  160.         CommentsBox.Text = temp.Fields("Comments").Value
  161.         If temp.Fields("Control").Value = "YES" Then
  162.             Thecontrolbox.Text = "Controlled"
  163.         Else
  164.             Thecontrolbox.Text = "Uncontrolled"
  165.         End If
  166.         UniqueID = UniqueIDBox.Text
  167.         Try
  168.             ImageDisplay.Image = System.Drawing.Image.FromFile(ADImageLocation & UniqueID & ".jpeg")
  169.             ImageDisplay.Visible = True
  170.             ImageDisplay.SizeMode = PictureBoxSizeMode.StretchImage
  171.         Catch
  172.             MsgBox("Image Not Found")
  173.         End Try
  174. End Sub
  175.  
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles