modifying data in MS Access

morgan

New member
Joined
Mar 11, 2009
Messages
2
Programming Experience
Beginner
I have a problem with modifying data in an access database. The Db contains a Balance field which I want to be able to add amounts to. This is as far as I have gotten

VB.NET:
Public Class Deposit

    Dim objDS As New DataSet
    Dim rowIndex As Integer = 0
    Dim objConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
    "Data Source=AccountDetails.accdb"

    Dim objSqlStr As String = "SELECT * FROM qryAllDetails"
    Dim objDA As New OleDb.OleDbDataAdapter(objSqlStr, objConn)




    Public Sub FillDetails()
        Dim objBalance As DataRow
        objBalance = objDS.Tables("Balance").Rows.Find(txtBalance)

    End Sub


    Private Function Adder(ByVal intNum1 As Integer, ByVal intNum2 As Integer) As Integer

        Dim answer As Integer

        answer = intNum1 + intNum2

        Return answer

    End Function



    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click


        Dim intNum1 As Integer = txtBalance.Text
        Dim intNum2 As Integer
        Dim intresult As Integer


        'assigns values
        intNum1 = Val(txtBalance.Text)
        intNum2 = Val(txtDeposit.Text)

        intresult = Adder(intNum1, intNum2)

        If intresult = 0 Then
            MessageBox.Show("No value entered, Please re-enter lodgement amount") 'validates amount is entered
        Else
            MessageBox.Show("Your new balance is" & intresult)
        End If

        txtNewBalance.Text = intresult


    End Sub

    Private Sub Deposit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objDA.Fill(objDS)
        Display() 'calls display

        FillDetails()

    End Sub

    Private Sub Display()


        'displays existing balance on screen when form loads
        Dim intNum1 As Integer = txtBalance.Text
        txtBalance.Text = intNum1
    End Sub


    Private Sub Retrieve()

        'clears dataset of any existing values
        objDS.Clear()
        'fills dataset with info from dataadapter
        objDA.Fill(objDS, "Balance")


    End Sub

End Class

The GUI has 3 three text boxes, one containing the current balance, second contains amount to be added and the third displays the new balance. I am unsure of how to retrieve the current balance and save it again! Any help would be greatly appreciated!

I am getting an error on this line of code also
VB.NET:
Dim intNum1 As Integer = txtBalance.Text

Please help :eek::eek:
 
1) You're genuinely puzzled as to why attempting to assign some TEXT into a variable that holds a NUMBER is giving an error? It's rather a square peg for a round hole, don't you think? :)

2) Read the DW2 link in my signature, section "creating a simple data app"
 
1)How can I take the value(which will only be numeric) from a textbox and use it in a calculation? How can I set it as a number?

2)I don't want to use wizards with the Db, so any help on what I've done would be great, unless it's really that bad that I should start over!:eek:
 
Last edited:
1. CONVERT the string to number. And handle exceptions (when somebody enters something that can not be converted to a number)
VB.NET:
Dim i As Integer
        Try
            i = Convert.ToInt32(justastring)
        Catch
            MsgBox("Conversion Error!")
            i = 0
        End Try
 

Latest posts

Back
Top