mardi 6 septembre 2016

Multiple If condition using Microsoft Access database in VB Net

I am trying to make a banking system where the customer will only be able to deposit money IF ONLY they enter the CORRECT AccountNo & Name using Microsoft Access Databse in VB NET.

Here are my codes:

Dim conn As New OleDbConnection

Dim conn = "provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\Database\Bank-Application-Database.accdb;"

    conn.ConnectionString = "provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\Database\Bank-Application-Database.accdb;"

    cmdupdate.Connection = cnnOLEDB

    Dim deposit As OleDbCommand = New OleDbCommand("SELECT * FROM [Current_Account] WHERE [AccountNo] and [CustomerName] = '" & accnotxt.Text & "' AND [CustomerName] = '" & nametxt.Text & "' AND [Amount] = '" & amounttxt.Text & "'", myConnection)
    deposit.Connection = conn
    conn.Open()


    If accnotxt.ToString = True And nametxt.ToString = True Then

        cmdupdate.CommandText = "UPDATE [Current_Account] SET [Amount] = '" & amounttxt.Text.ToString & " WHERE [AccountNo] AND [CustomerName] = " & accnotxt.Text.ToString & " " & nametxt.ToString & ";"
        cmdupdate.CommandType = CommandType.Text
        cmdupdate.ExecuteNonQuery()
        MsgBox(" Successfully deposited.")
    Else
        MsgBox("Incorrect Account Number or Name.")

I am able to run.However when I click to Deposit, this is the error.

The error I got:

An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

Additional information: Conversion from string "System.Windows.Forms.TextBox, Te" to type 'Boolean' is not valid.

Any helpers ? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire