我正在尝试使用带有访问数据库的vb.net创建银行系统 [英] I am trying to create a banking system using vb.net with access database

查看:139
本文介绍了我正在尝试使用带有访问数据库的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 * from NewAccount where Saccountno = '" + TextBox1.Text + "'", cn)
        rs.Fill(dt)
        If dt.Tables(0).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()
        End If
        Return 0
    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



我尝试过的事情:

我正在尝试减少Access数据库中的当前余额,问题是当我单击button1时,结果始终是if val(withBox.text)Statement



What I have tried:

I am trying to reduce my current balance in access database, the problem is when i click button1 the result is always the if val(withBox.text) Statement

推荐答案

入门者,切勿串联字符串以构建SQL命令.它使您对意外或蓄意的SQL注入攻击敞开大门,这可能会破坏整个数据库.请改用参数化查询.
修复此问题后,请使用调试器.
进行重大更改以使调试更加容易:
更改
For starters, never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Once you have fixed that, use the debugger.
Make a trivial change to make debugging easier:
Change
If Val(WithBox.Text) > bal Then
    LowerBalance.Show()


Dim wb = Val(WithBox.Text)
If wb > bal Then
    LowerBalance.Show()


在Button1_Click处理程序的第一行上放置一个断点,然后运行程序.
现在单步执行代码,观察变量发生了什么.仔细检查它们包含的内容,并弄清楚代码的结果,然后再逐步执行每一行.它符合您的预期吗?如果是这样,继续前进.如果没有...为什么不呢?如果仔细查看正在发生的情况,应该清楚地知道问题出在哪里.


Put a breakpoint on the first line of the Button1_Click handler, and run your program.
Now step over the code and watch what happens to your variables. Look ate exactly what they contain, and work out what the code should do as a result, before you step each line. Did it do what you expected? If so, move on. If not...why not? It should be reasonably obvious what the problem is if you look carefully at what is happening.


这篇关于我正在尝试使用带有访问数据库的vb.net创建银行系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆