In Ms Access, I have a Customer table and a Credit Card table. The CustomerID field is a primary key in the Credit Card table. Both tables already have sample data in it.
So, when a customer wants to purchase a product, they proceed to checkout and payment. They fill out the payment form where their credit card information is inputted.
When the customer submits the form , the system checks to see if the information is already in the database. If it is, the user is directed to the Payment Approved page. However, if the information is not already in the Credit Card table then it has to be inputted.
The customer would already have a customerid when they register. The customerid in the customer table is an autonumber. the one in the credit card table is a number datatype.
I am trying to put the information in the database using the code below but nothing is going in. It goes directly to the Payment Approved page.
Expand|Select|Wrap|Line Numbers
- Protected Sub BTNProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTNProcess.Click
- Dim myShoppingCart As ShoppingCart
- myShoppingCart = DirectCast(Session("ShoppingCart"), ShoppingCart)
- Dim no As String
- no = Me.TextBox2.Text.Trim()
- Dim connectionstring As String
- connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("GameDB.mdb")
- Using connection As New OleDbConnection(connectionstring)
- connection.Open()
- Dim cmdText As String = "SELECT * FROM CreditCard;"
- Dim command As OleDbCommand
- command = New OleDbCommand(cmdText, connection)
- Dim reader As OleDbDataReader
- reader = command.ExecuteReader
- If reader.HasRows Then
- Response.Redirect("PaymentApproved.aspx")
- Return
- Else
- Dim cn As String = TextBox2.Text
- Dim em As String = DDLMonth.Text
- Dim ey As String = DDLYear.Text
- Dim fn As String = TextBox1.Text
- Dim ln As String = TextBox4.Text
- Dim ba As String = TextBox5.Text
- Dim autonumber As Integer
- Dim check As Integer
- check = Microsoft.VisualBasic.Val("CCID")
- If check < Microsoft.VisualBasic.Val("CCID") Then
- autonumber = check
- End If
- Dim CID As String
- Session("SessionUser") = ("CustomerID").ToString
- CID = Session("SessionUser")
- cmdText = "INSERT INTO CreditCard (CCNumber, CustomerID, CCExpireMonth, CCExpireYear, CCFirstName, CCLastName, BillingAddress) VALUES ('" + cn + "','" + CID + "','" + em + "','" + ey + "','" + fn + "','" + ln + "','" + ba + "')"
- command = New OleDbCommand(cmdText, connection)
- command.ExecuteNonQuery()
- Response.Redirect("PaymentApproved.aspx")
- End If
- End Using
- End Sub
I think it is the foreign key that is giving the problem because the foreign key has to be the customerid. So how do I get that from the session user. Or it might be something else that is the problem.
Can anyone help me?