Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB.NET
Imports System.Data.OleDb
Imports System.Data
Public Class WithdrawandDeposit2
    Dim adapt As New OleDbDataAdapter
    Dim dset As New DataSet
    Dim bal, num As String
    Dim total As Integer
    Function draw()
        cn = New OleDb.OleDbConnection
        With cn
            .ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Maccount.accdb"
            .Open()
        End With
        Dim dt As New DataSet("NewAccount")
        'Dim rs As New OleDb.OleDbDataAdapter(" Select Samount from NewAccount where Samount = '" + lblamount.Text + "'", cn)
        Dim rs As New OleDb.OleDbDataAdapter(" Select * from NewAccount where Saccountno = '" + TextBox1.Text + "'", cn)
        rs.Fill(dt)
        If .Tables(dt).rows.count > 0 Then
            bal = dt.Tables(0).Rows(0)(6).ToString()
            num = dt.Tables(0).Rows(0)(0).ToString()
            TextBox2.Text = dt.Tables(0).Rows(0)(2).ToString()
            Return 0
        End If
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Val(WithBox.Text) > bal Then
            LowerBalance.Show()
        ElseIf Me.WithBox.Text = "" Then
            Errorform1.Show()
        Else
            total = bal - Val(WithBox.Text)
            Dim dbcommand As String = "update NewAccount set Samount = '" & total & "'where AccountName='" & TextBox1.Text & "'"
            adapt = New OleDbDataAdapter(dbcommand, cn)
            dset = New DataSet
            adapt.Fill(dset)
            'rs.Dispose()
            'cn.Close()
            Call draw()

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
        Transactions.Show()
    End Sub

    Private Sub WithdrawandDeposit2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call draw()
        TextBox2.Enabled = False
    End Sub
End Class


What I have tried:

i am getting an error in bal = dt.tables(0).rows(0)(6).ToString()
Posted
Updated 8-Mar-16 3:32am
v2

1 solution

It's as simple as the error message states: There is no row at row-index 0 of that table. The table is empty. At the line above you seem to check for the row count but it's apparently a different table you're checking there. Maybe it should look like this instead?:

VB
If dt.Tables(0).Rows.Count > 0 Then
 
Share this answer
 
Comments
CaptainChizni 8-Mar-16 9:40am    
Thanks it works :)
Sascha Lefèvre 8-Mar-16 9:53am    
You're welcome! :)
CaptainChizni 8-Mar-16 10:02am    
One more question i am trying to create a banking system, the problem is when i click the button1 it only executes the if val(withbox.text) statement, how can i decrease my balance in access
Sascha Lefèvre 8-Mar-16 10:20am    
bal is a string, Val(WithBox.Text) is a number - so Val(WithBox.Text) > bal is comparing a number to a string which is probably the problem here.

I suggest you use Option Strict which disallows you to even compile such statements and thus will improve your code quality. At first you'll most probably have several places where you'll have to fix stuff but you'll avoid problems like these!

See here: https://msdn.microsoft.com/en-us/library/zcd4xwzs.aspx

And on the same note, Option Explicit:
https://msdn.microsoft.com/en-us/library/y9341s4f.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900