• 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

    • My father still uses a programme written in dbase3. Still manages to work with a little help from dosbox. 
    • Microsoft hides these secret Windows 11 performance boost settings available on every PC by Sayan Sen Windows enthusiasts often look for ways to extract as much performance out of their systems as possible, and it's often the case that they try and do so while trying to minimize the heat and power consumption. This is especially relevant in the case of mobile Windows PCs since laptops and notebooks tend to get hot and management of that heat and power is harder in such a form factor. As such users often turn to techniques like under-volting which can be used to squeeze out the maximum capabilities of a chip while also maintaining lowered power levels. There are official apps from AMD and Intel with the likes of Ryzen Master and XTU (Extreme Tuning Utility). While these are quite handy, most enthusiasts probably prefer to dig into the BIOS and play around with settings there like Curve Optimizer on Ryzen, which lets users set various frequency-voltage scaling values. These are essentially called P-States. If you are not familiar with them, Processor Power Management is done through Advanced Configuration and Power Interface (ACPI) P-states and C-states. While P-states or performance pwoer states handle CPU voltage-frequency scaling, C-states deal with CPU sleep states so that some of the CPU functions, which are not necessary at that moment, can be disabled. The P-states and C-states work together to make the processor run more efficiently. It helps the OS and apps determine which cores can be parked and which should be boosted. Of course not every user is an enthusiast or knows the technicalities and integrities of how things like overclocking or undervolting work. Thankfully for them Windows itself offers something pretty cool, though it is hidden by default on all systems. By default, Windows only has two P-States, "Minimum Processor State" and "Maximum Processor State." However, this can be changed with a Registry trick to expand the options under a secret "Processor performance boost mode" dropdown. This essentially enables the HWP or hardware P-States available on a device, and these are not controlled just by the OS itself as the underlying hardware gets involved too. In total there are five Processor Performance Boost Mode profiles that control how Windows requests and allows CPU turbo/boost behavior under the different power policies. They are: Disabled: In this mode, processor boosting is effectively turned off. The CPU will avoid entering turbo or boost frequencies and instead operate closer to its base frequency ceiling. This can significantly reduce power consumption and heat output, but at the cost of reduced burst performance and responsiveness in short workloads. Enabled: This is the standard behavior where boost functionality is allowed under normal conditions. The processor can opportunistically increase frequency when workload demands it, balancing performance gains with power and thermal constraints as managed by the system. Aggressive: Aggressive mode favors performance more heavily, allowing the CPU to enter higher boost states more readily and sustain them longer. This should in theory improve responsiveness under bursty or heavy workloads but increases power draw and thermal output compared to the default enabled behavior. Efficient Enabled: This mode still allows boosting, but with a stronger bias toward energy efficiency. The system attempts to use boost more selectively, avoiding unnecessary frequency spikes when the performance gain is marginal. Efficient Aggressive: This is a hybrid approach where boost is still performance-responsive, but the system continuously weighs efficiency more heavily than in Aggressive mode. It aims to deliver noticeable performance improvements while reducing wasted power in less demanding scenarios. Here's how to enable the Processor performance boost mode: Open Registry Editor: Press Win+R, type regedit, and click OK. Go to: HKLM\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\54533251-82be-4824-96c1-47b60b740d00\be337238-0d82-4146-a960-4f3749d470c7 (where HKLM stands for HKEY_LOCAL_MACHINE_) Modify the value of Attributes from 1 to 2 (you can find modify option by right-clicking) After that, exit Registry, you should now be able to see the new "Processor performance boost mode" dropdown menu: As you can see there are now five new P-States or CPPC states or power profile available that help define the boost mode processor setting on your PC. Wrapping it up here's a quick run-down of the settings as defined by Microsoft itself. Setting Description Disabled The corresponding P-state-based behaviour is disabled. Collaborative Processor Performance Control (CPPC) behaviour is disabled. Enabled The corresponding P-state-based behaviour is enabled. CPPC behaviour is Efficient Enabled. Aggressive The corresponding P-state-based behaviour is enabled. CPPC behaviour is Aggressive. Efficient Enabled The corresponding P-state-based behaviour is Efficient. CPPC behaviour is Efficient Enabled. Efficient Aggressive The corresponding P-state-based behaviour is Efficient. CPPC behaviour is Aggressive. Aggressive At Guaranteed Windows calculates the desired extra performance above the guaranteed performance level, and asks the processor to deliver that specific performance level. Efficient Aggressive At Guaranteed Windows always asks the processor to deliver the highest possible performance above the guaranteed performance level. In the next part we shall be comparing these settings to explore how much of a benefit or regression they can provide in terms of performance and power efficiency. If you decide to change the values on your system and are experiencing problems like crashes or an overheating PC, make sure to revert the steps back to the original state.
    • I think he means you haven't reviewed previous UFC games. Of course it doesn't matter... Every time you just report on something that involves the President even if just simply what happened you guys usually get accused of being anti-Trump. We live in fun times.
    • So how did you solve the problem? Disabling Secure Boot isn’t a solution.
  • Recent Achievements

    • 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
    • One Month Later
      agatameier earned a badge
      One Month Later
    • Week One Done
      agatameier earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      518
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      147
    4. 4
      ATLien_0
      93
    5. 5
      Steven P.
      77
  • Tell a friend

    Love Neowin? Tell a friend!