Results 1 to 4 of 4

Thread: How to make data reader/obj reader valid in program code?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    3

    How to make data reader/obj reader valid in program code?

    Anyone knows???

  2. #2
    New Member
    Join Date
    Apr 2004
    Posts
    12

    Need more info....

    I am not sure what you are asking, could you more specific about what it is you are trying to do and how you want it to work?

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    3
    I want the program to be able to retrieve the specific record from the data base.
    Also, to be able to calculate the GPA from the academic record database.

  4. #4
    New Member
    Join Date
    Apr 2004
    Posts
    12

    assumptions

    I am still not entirly sure how this should be setup b/c you weren't very clear what tables you had and how they where setup, or how you wanted the end result to be displayed but you should be able to adapt this to what you need. If you don't understand what is going on let me know. I also assume you know that you have to connect to the database through the server explorer first. If you don't know how to do that then let me know and I will post instructions on how to do that.

    Public Class Form1
    Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "


    'Declare Variables
    Dim dt As New DataTable() 'creates new datatable
    Dim connstr As String = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = People.MDB " 'defines connection to db
    Dim sqlStr As String = "Select * from Records" 'sql statement to select all records from Records table
    Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connstr) 'creates data adpater to load information into datatable
    Dim Counter, a As Integer 'creates counters

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Load information from table into datatable
    dataAdapter.Fill(dt)
    dataAdapter.Dispose()

    'sets value of a
    a = dt.Rows.Count - 1

    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    'Declare Variables
    Dim FName, LGrade1, LGrade2, LGrade3, LGrade4 As String
    Dim Grade1, Grade2, Grade3, Grade4, GPA As Integer
    Dim i As Integer
    Dim personFound As Boolean = False
    'input box for person to search for
    FName = InputBox("Enter the First Name of the person to search for.")
    'searches through datatable for match
    For i = 0 To (dt.Rows.Count - 1)
    'if found loads rowindex's records into textboxes
    If CStr(dt.Rows(i)(1)) = FName Then
    personFound = True
    Counter = i
    txtFName.Text = dt.Rows(Counter)(1)
    txtLName.Text = dt.Rows(Counter)(0)
    LGrade1 = dt.Rows(Counter)(2)
    LGrade2 = dt.Rows(Counter)(3)
    If LGrade1 = "A" Then 'this determines the grade point value of the grade for the first grade
    Grade1 = 12
    Else
    If LGrade1 = "B" Then
    Grade1 = 9
    Else
    If LGrade1 = "C" Then
    Grade1 = 6
    Else
    If LGrade1 = "D" Then
    Grade1 = 3
    Else
    Grade1 = 0
    End If
    End If
    End If
    End If
    If LGrade2 = "A" Then 'this determines the grade point value of the grade for the second grade
    Grade2 = 12
    Else
    If LGrade2 = "B" Then
    Grade2 = 9
    Else
    If LGrade2 = "C" Then
    Grade2 = 6
    Else
    If LGrade2 = "D" Then
    Grade2 = 3
    Else
    Grade2 = 0
    End If
    End If
    End If
    End If
    End If
    GPA = (Grade1 + Grade2) / 6 'this assumes both classes are worth 3 credit hours
    txtGPA.text = GPA
    Next
    'not found displays messagebox stating could not find
    If (Not personFound) Then
    MsgBox("Cannot find the requested person")
    End If

    End Sub

    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width