borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Classic problem: print sales invoice on continuous form using VB 2005 and LX 300)Next Topic (.NET Framework Error Message) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : database visual basic 2005 Solved Topic
Poster Message
eira_ak
Level: Protégé

Registered: 08-03-2007
Posts: 8

icon database visual basic 2005

i'm using visual basic 2005 express edition...
anybody can help me..
why the data not added to the database?
its just say.."data added to database but when i check the m.acces there's have no data been added...
please help me..
same with delete and update??

my coding is like these:

Imports System.Data

Public Class frmAdd
    Dim inc As Integer
    Dim maxRows As Integer
    Dim conObj As New OleDb.OleDbConnection
    Dim adpStudent As New OleDb.OleDbDataAdapter
    Dim ABSENTEEISM_REPORT_SYSTEMDataSet As New DataSet
    Dim sql As String
    Dim cboProgramme As New ComboBox
    Dim cboSemester As New ComboBox


    Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sql As String
        conObj.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ABSENTEEISM REPORT SYSTEM.mdb"
        conObj.Open()

        sql = "SELECT * FROM Student"

        If cboProgramme.Text = "COV1" Then
            sql = "SELECT * FROM Student WHERE ProgrammeID = COV1"
        ElseIf cboProgramme.Text = "COV2" Then
            sql = "SELECT * FROM Student WHERE ProgrammeID = COV2"
        ElseIf cboProgramme.Text = "DSK-UPM" Then
            sql = "SELECT * FROM Student WHERE ProgrammeID = DSK-UPM"
        End If

        

        adpStudent = New OleDb.OleDbDataAdapter(sql, conObj)
        adpStudent.Fill(ABSENTEEISM_REPORT_SYSTEMDataSet, "Student")
        conObj.Close()
        maxRows = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows.Count
        inc = -1

    End Sub

    Private Sub NavigateRecords()

        txtIC.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(0)
        txtID.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(1)
        txtProg.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(2)
        txtName.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(3)
        txtAddress.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(4)
        txtSubject.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(5)
        txtProgramme.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(6)
        txtSemester.Text = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Item(7)


    End Sub



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

    Private Sub cmdPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrevious.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 cmdLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLast.Click
        If inc <> maxRows - 1 Then
            inc = maxRows - 1
            NavigateRecords()
        End If
    End Sub

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

    Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
        NavigateRecords()

        Dim cb As New OleDb.OleDbCommandBuilder(adpStudent)

        adpStudent.Update(ABSENTEEISM_REPORT_SYSTEMDataSet, "Student")
        NavigateRecords()

        MsgBox("Data updated")

    End Sub

    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        cmdCommit.Enabled = True
        cmdAdd.Enabled = False
        cmdDelete.Enabled = False
        cmdClear.Enabled = False
        cmdUpdate.Enabled = False


        txtIC.Clear()

        txtID.Clear()

        txtProg.Clear()

        txtName.Clear()

        txtAddress.Clear()

        txtSubject.Clear()

        txtProgramme.Clear()

        txtSemester.Clear()
      
    End Sub

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

            Dim cb As New OleDb.OleDbCommandBuilder(adpStudent)

            ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows(inc).Delete()
            maxRows = maxRows - 1

            inc = 0
            NavigateRecords()


            adpStudent.Update(ABSENTEEISM_REPORT_SYSTEMDataSet, "Student")


            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
        End If
    End Sub

    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click

        cmdCommit.Enabled = False
        cmdAdd.Enabled = True
        cmdDelete.Enabled = True
        cmdClear.Enabled = True
        cmdUpdate.Enabled = True

        inc = 0
        txtIC.Clear()

        txtID.Clear()

        txtProg.Clear()

        txtName.Clear()

        txtAddress.Clear()

        txtSubject.Clear()

        txtProgramme.Clear()

        txtSemester.Clear()


    End Sub



    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        End
    End Sub

    Private Sub cmdCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCommit.Click


        If inc <> -1 Then

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

            dsNewRow = ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").NewRow()

            dsNewRow.Item("StudentIC") = txtIC.Text
            dsNewRow.Item("StudentID") = txtID.Text
            dsNewRow.Item("ProgrammeID") = txtProg.Text
            dsNewRow.Item("StudentName") = txtName.Text
            dsNewRow.Item("Address") = txtAddress.Text
            dsNewRow.Item("Subject") = txtSubject.Text
            dsNewRow.Item("Programme") = txtProgramme.Text
            dsNewRow.Item("Semester") = txtSemester.Text

          

            ABSENTEEISM_REPORT_SYSTEMDataSet.Tables("Student").Rows.Add(dsNewRow)


            adpStudent.Update(ABSENTEEISM_REPORT_SYSTEMDataSet, "Student")


            MsgBox("New Record added to the Database")

            cmdCommit.Enabled = False
            cmdAdd.Enabled = True
            cmdDelete.Enabled = True
            cmdClear.Enabled = True
            cmdUpdate.Enabled = True
        End If
    End Sub

End Class

06-04-2007 at 06:34 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
eira_ak
Level: Protégé

Registered: 08-03-2007
Posts: 8
icon Re: database visual basic 2005

i just got it by myself..

27-04-2007 at 07:34 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB.Net : database visual basic 2005 Solved Topic
Previous Topic (Classic problem: print sales invoice on continuous form using VB 2005 and LX 300)Next Topic (.NET Framework Error Message) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder