• 0

Newbie, VB help


Question

Hi guys Im building a program for an assignment, but this is really bugging me now been at it for hrs and still cant work it out, Ive done it on my other1 but this 1 aint having it

Basically I need to connect my prog to MS access database "project" where i have 4 tables and I am trying to connect to 1 of them "ExhibitorCompanies", Can any1 tell me where i've gone wrong please?

Here's what ive done....

Public Class Form1

Dim con As New OleDb.OleDbConnection

Dim dbProvider As String

Dim dbSource As String

Dim ds As New DataSet

Dim da As OleDb.OleDbDataAdapter

Dim sql As String

Dim inc As String

Dim MaxRows As Integer

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)

dbProvider = "PROVIDER=Microsoft.ace.OLEDB.12.0;"

dbSource = "Data Source = Project.accdb"

con.ConnectionString = dbProvider & dbSource

con.Open()

sql = "SELECT * FROM ExhibitorCompanies"

da = New OleDb.OleDbDataAdapter(sql, con)

da.Fill(ds, "Project")

con.Close()

MaxRows = ds.Tables("ExibitorCompanies").Rows.Count

inc = -1

End Sub

Private Sub navigateRecords()

TxtCompid.Text = ds.Tables("ExibitorCompanies").Rows(inc).Item(0)

TxtCompName.Text = ds.Tables("ExibitorCompanies").Rows(inc).Item(1)

TxtAddress.Text = ds.Tables("ExibitorCompanies").Rows(inc).Item(2)

TxtCity.Text = ds.Tables("ExibitorCompanies").Rows(inc).Item(3)

TxtTelNumb.Text = ds.Tables("ExibitorCompanies").Rows(inc).Item(4)

TxtNumbStands.Text = ds.Tables("ExibitorCompanies").Rows(inc).Item(5)

TxtPrice.Text = ds.Tables("ExibitorCompanies").Rows(inc).Item(6)

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 BtnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrev.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 btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

Dim cb As New OleDb.OleDbCommandBuilder(da)

ds.Tables("ExibitorCompanies").Rows(inc).Item(0) = TxtCompid.Text

ds.Tables("ExibitorCompanies").Rows(inc).Item(1) = TxtCompName.Text

ds.Tables("ExibitorCompanies").Rows(inc).Item(2) = TxtAddress.Text

ds.Tables("ExibitorCompanies").Rows(inc).Item(3) = TxtCity.Text

ds.Tables("ExibitorCompanies").Rows(inc).Item(4) = TxtTelNumb.Text

ds.Tables("ExibitorCompanies").Rows(inc).Item(5) = TxtNumbStands.Text

ds.Tables("ExibitorCompanies").Rows(inc).Item(6) = TxtPrice.Text

da.Update(ds, "ExibitorCompanies")

MsgBox("Data Updated")

End Sub

Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNew.Click

BtnCommit.Enabled = True

BtnNew.Enabled = False

BtnUpdate.Enabled = False

BtnDelete.Enabled = False

TxtCompid.Clear()

TxtCompName.Clear()

TxtAddress.Clear()

TxtCity.Clear()

TxtTelNumb.Clear()

TxtNumbStands.Clear()

TxtPrice.Clear()

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

BtnCommit.Enabled = False

BtnNew.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("Project").NewRow()

dsNewRow.Item("Company ID") = TxtCompid.Text

dsNewRow.Item("Company Name") = TxtCompName.Text

dsNewRow.Item("Address") = txtaddress.Text

dsNewRow.Item("City") = TxtCity.Text

dsNewRow.Item("Telephone Number") = TxtTelNumb.Text

dsNewRow.Item("Number of Stands") = TxtNumbStands.Text

dsNewRow.Item("Price of Stands") = TxtPrice.Text

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

da.Update(ds, "ExibitorCompanies")

MsgBox("New Record added to the Database")

BtnCommit.Enabled = False

BtnNew.Enabled = True

btnUpdate.Enabled = True

btnDelete.Enabled = True

End If

End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

Dim cb As New OleDb.OleDbCommandBuilder(da)

If MessageBox.Show("Please confirm you want to Delete this Record?", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then

MsgBox("Operation Canceled")

Exit Sub

End If

ds.Tables("ExibitorCompanies").Rows(inc).Delete()

MaxRows = MaxRows - 1

inc = 0

navigateRecords()

da.Update(ds, "ExibitorCompanies")

End Sub

End Class

Link to comment
https://www.neowin.net/forum/topic/1134984-newbie-vb-help/
Share on other sites

3 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • AMAZON needs to take total accountability for this.
    • Server Summit had a heap of announcements, ADCS changes are baller.
    • Nice, hope they *finally* fixed the issue with the NTFS driver where the system would completely brick during large file copies using the built in driver. It's been broken for years requiring me to use the older, slower, NTFS-3G FUSE driver.
    • Windows 11 KB5094126 BSODing, freezing, forcing BitLocker lockout, breaks OneDrive, and more by Sayan Sen Microsoft released Windows 11 KB5094126 and KB5093998 last week as the latest Patch Tuesday updates. Following that the company also published the accompanying dynamic updates under KB5094149, KB5095971, and KB5094156. While Microsoft has so far not acknowledged any major problems with the release, some users online are running into problems. These range from OneDrive and Dropbox access issues, BitLocker recovery lockouts, to blue screens and BSODs. The most common one seems to be happening with HP systems wherein affected users say they hit 0xc0430001 BSOD (blue screen of death) error code after the KB5094126 update. We wonder if this could be related to the recent bug we covered on HP devices wherein the ongoing Secure Boot certificate updates are leading to similar issues. While we are not certain, users affected by this issue likely need to ensure that the boot.stl file is included on the installation media (such as a USB installer or ISO), if the above-mentioned dynamic updates are deployed. If this file is missing, computers may fail to boot from the installation media and could display the error 0xc0430001. This STL file is used by Secure Boot to verify that the boot files are trusted, so it must match the same Windows version and system architecture. To ensure the file is included, Microsoft recommends using the Update WinPE script, which automatically updates the image and handles the required files. Alternatively, you can manually copy the boot.stl file from the Windows\Boot\EFI folder on a Windows device and place it in the matching folder on your installation media before deploying the updated image. Aside from blue screening some users also note their systems have been freezing following the update. This could be happening to Lenovo PCs specifically. In the case of the OneDrive and Dropbox access issues, a user figured out that there could be a conflict with UAC. He explained: "Okay, so I did some digging, and in our environment KB5094126 breaks OneDrive and Dropbox in Explorer. I went through all our GPOs and found out that the combination of disabling UAC and having my user being a local admin breaks OneDrive in Explorer. ... If I enable UAC again, then it works, even with KB5094126 still installed." Hopefully, Microsoft will look into these issues. Source: Microsoft forum (link1, link2, link3, link4), Reddit (link1, link2, link3, link4)
    • It is when it's a desktop in my house though for a PC that's lightly used and not really important when it is. If it was a laptop, it would be a different story. The real solution is varied and begins starting at post #22 in that thread.
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      138
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      80
  • Tell a friend

    Love Neowin? Tell a friend!