2 Replies - 8481 Views - Last Post: 12 April 2010 - 02:34 PM Rate Topic: -----

#1 susieq  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 16-February 10

Library Management System

Posted 11 April 2010 - 06:24 PM

Hi Everyone

I am working on an assignment for a library Management System. I have created my tables in access and I am trying to connect the database to vb.net. I was away from class for a while because I was in the hospital. I am trying to catch up I worked the example given in class and the programme run. I copied the code and put in the assignment the only thing i changed was the names now it is not running. I need help it is due on the 22 of April. this is my code

Imports System.Data
Public Class Loan
    Dim inc As Integer
    Dim MaxRows As Integer
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    ' Dim cb As New OleDb.OleDbCommandBuilder(da)

    Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click
        Dim con As New OleDb.OleDbConnection


        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Family\Desktop\K_S.mdb"
        con.Open()
        sql = "SELECT * FROM tblLoan"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "k_S")


        con.Close()


        MaxRows = ds.Tables("K_S").Rows.Count
        inc = -1

    End Sub
    Private Sub NavigateRecords()

        txtisbn.Text = ds.Tables("K_S").Rows(inc).Item(1)
        txtloancardnumber.Text = ds.Tables("K_S").Rows(inc).Item(2)
        txtloandate.Text = ds.Tables("K_S").Rows(inc).Item(3)
        txtreturndate.Text = ds.Tables("K_S").Rows(inc).Item(4)
        chkonloan.Text = ds.Tables("K_S").Rows(inc).Item(5)
    End Sub


    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If inc <> MaxRows - 1 Then
            inc = inc + 1
            NavigateRecords()
        Else
            MsgBox("No More Rows")
        End If
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If inc > 0 Then
            inc = inc - 1
            NavigateRecords()
        ElseIf inc = -1 Then
            MsgBox("No Records Yet")
        ElseIf inc = 0 Then
            MsgBox("First Record")
        End If
    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        If inc <> 0 Then
            inc = 0
            NavigateRecords()
        End If
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        If inc <> MaxRows - 1 Then
            inc = MaxRows - 1
            NavigateRecords()
        End If
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddnew.Click
        btnCommit.Enabled = True
        btnAddNew.Enabled = False
        btnUpdate.Enabled = False
        btndelete.Enabled = False

        txtisbn.Clear()
        txtloancardnumber.Clear()
        txtloandate.Clear()
        txtreturndate.Clear()
    End Sub

    Private Sub btnClaear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        btnCommit.Enabled = False
        btnaddnew.Enabled = True
        btnUpdate.Enabled = True
        btndelete.Enabled = True

        inc = 0
        NavigateRecords()
    End Sub

    Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommit.Click
        If inc <> -1 Then

            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow

            dsNewRow = ds.Tables("AddressBook").NewRow()

            dsNewRow.Item("ISBN") = txtisbn.Text
            dsNewRow.Item("Loan Card Number") = txtloancardnumber.Text
            dsNewRow.Item("Loan Date") = txtloandate.Text
            dsNewRow.Item("REturn Date") = txtreturndate.Text
            

            ds.Tables("K_S").Rows.Add(dsNewRow)

            da.Update(ds, "K_S")

            MsgBox("New Record added to the Database")

            btnCommit.Enabled = False
            btnaddnew.Enabled = True
            btnUpdate.Enabled = True
            btndelete.Enabled = True

        End If
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        ds.Tables("K_S").Rows(inc).Item(1) = txtisbn.Text
        ds.Tables("K_Sk").Rows(inc).Item(2) = txtloancardnumber.Text
        ds.Tables("K_S").Rows(inc).Item(3) = txtloandate.Text
        ds.Tables("K_S").Rows(inc).Item(4) = txtreturndate.Text
        ' da.Update(ds, "AddressBook")
        MsgBox("Data updated")
    End Sub

    Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
        If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, _
MessageBoxIcon.Warning) = DialogResult.No Then


            MsgBox("Operation Cancelled")
            Exit Sub

        End If
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("K_S").Rows(inc).Delete()
        MaxRows = MaxRows - 1

        inc = 0
        NavigateRecords()
        da.Update(ds, "K_S")
    End Sub
End Class

This post has been edited by JackOfAllTrades: 11 April 2010 - 06:29 PM
Reason for edit:: Added code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Library Management System

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Library Management System

Posted 11 April 2010 - 06:30 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 susieq  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 16-February 10

Re: Library Management System

Posted 12 April 2010 - 02:34 PM

It does not display the information when I load the form
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1