dimanche 2 février 2020

How can I add data of one record in access through two queries?

Dim todaydate As String = String.Format("{0:dd/MM/yyyy}", DateTime.Now)
        Dim expdate As String = String.Format("{0:dd/MM/yyyy}", dtpexpdate.Value)
        Dim ordersql As String
        ordersql = "Insert into SalesTable([BookID],[Username],[Phone No],[Address],[Payment method],[SaleDate]) Values(?,?,?,?,?,?)"
        conn.Open()
        Dim cmd As New OleDbCommand(ordersql, conn)
        cmd.Parameters.AddWithValue("@BookID", lbid.Text)
        cmd.Parameters.AddWithValue("@Username", txtusernm.Text)
        cmd.Parameters.AddWithValue("@Phone No", txtphone.Text)
        cmd.Parameters.AddWithValue("@Address", txtaddr.Text)
        cmd.Parameters.AddWithValue("@Payment method", cbpaymeth.Text)
        cmd.Parameters.AddWithValue("@SaleDate", todaydate)
        cmd.ExecuteNonQuery()
        MsgBox("1st Done!")

        Dim order2sql As String
        order2sql = "Insert into SalesTable([Payment status],[Card No],[Expiry Date]) Values(?,?,?) Where BookID='" & lbid.Text & "'AND Username='" & txtusernm.Text & "'"

        If cbpaymeth.Text Like "Cash-on-Delivery" Then
            Dim cmd2 As New OleDbCommand(order2sql, conn)
            cmd2.Parameters.AddWithValue("@Payment status", False)
            cmd2.Parameters.AddWithValue("@Card No", 0)
            cmd2.Parameters.AddWithValue("@Expiry Date", "")
            cmd2.ExecuteNonQuery()
            MsgBox("2nd Do-o-one")
        Else
            Dim cmd2 As New OleDbCommand(order2sql, conn)
            cmd2.Parameters.AddWithValue("@Payment status", True)
            cmd2.Parameters.AddWithValue("@Card No", txtcardno.Text)
            cmd2.Parameters.AddWithValue("@Expiry Date", expdate)
            cmd2.ExecuteNonQuery()
            MsgBox("2nd Done")
        End If

        Dim quansql As String
        quansql = "Update BooksTable Set Quantity = Quantity-1 Where [BookID]= '" & lbid.Text & "'"
        Dim cm As New OleDbCommand(quansql, conn)
        cm.ExecuteNonQuery()
        conn.Close()
        MsgBox("Your Order has been Placed", vbExclamation)

When I select 'Cash-on-delivery' in the combobox for the payment method value and click the button, the ordersql query command is executed successfully with its parameters but the 1st set of code for the if condition shows an error "Query input must contain at least one table or query" at the cmd2.ExecuteNonQuery() line.

When I select 'Credit/Debit Card', nothing happens at all no matter how many times I click the button.

Can anyone show me how to add the data of one record through two queries using a simple code?

Aucun commentaire:

Enregistrer un commentaire