473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

inputting information when there is a foreign key

7
Hi all,


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
  1. Protected Sub BTNProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTNProcess.Click
  2.  
  3. Dim myShoppingCart As ShoppingCart
  4.  
  5. myShoppingCart = DirectCast(Session("ShoppingCart"), ShoppingCart)
  6.  
  7. Dim no As String
  8.  
  9. no = Me.TextBox2.Text.Trim()
  10.  
  11. Dim connectionstring As String
  12. connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("GameDB.mdb")
  13.  
  14. Using connection As New OleDbConnection(connectionstring)
  15. connection.Open()
  16.  
  17. Dim cmdText As String = "SELECT * FROM CreditCard;"
  18. Dim command As OleDbCommand
  19. command = New OleDbCommand(cmdText, connection)
  20. Dim reader As OleDbDataReader
  21. reader = command.ExecuteReader
  22.  
  23. If reader.HasRows Then
  24. Response.Redirect("PaymentApproved.aspx")
  25.  
  26. Return
  27.  
  28. Else
  29.  
  30. Dim cn As String = TextBox2.Text
  31. Dim em As String = DDLMonth.Text
  32. Dim ey As String = DDLYear.Text
  33. Dim fn As String = TextBox1.Text
  34. Dim ln As String = TextBox4.Text
  35. Dim ba As String = TextBox5.Text
  36. Dim autonumber As Integer
  37.  
  38. Dim check As Integer
  39. check = Microsoft.VisualBasic.Val("CCID")
  40.  
  41.  If check < Microsoft.VisualBasic.Val("CCID") Then
  42.  
  43. autonumber = check
  44.  
  45.  End If
  46.  
  47. Dim CID As String
  48.  
  49. Session("SessionUser") = ("CustomerID").ToString
  50.  
  51. CID = Session("SessionUser")
  52.  
  53. cmdText = "INSERT INTO CreditCard (CCNumber, CustomerID, CCExpireMonth, CCExpireYear, CCFirstName, CCLastName, BillingAddress) VALUES ('" + cn + "','" + CID + "','" + em + "','" + ey + "','" + fn + "','" + ln + "','" + ba + "')"
  54.  
  55. command = New OleDbCommand(cmdText, connection)
  56. command.ExecuteNonQuery()
  57. Response.Redirect("PaymentApproved.aspx")
  58.  
  59.  End If
  60.  
  61.  End Using
  62.  
  63.  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?
Aug 7 '08 #1
0 926

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeremiah Jacks | last post by:
I just upgraded to MySQL 4.0.14-standard for RedHat Linux and am using = the pre-compiled binaries. I have a database with INNODB tables. When I insert a row into one of the child tables, I get...
13
by: Immanuel Goldstein | last post by:
Obtained under the Freedom of Information Act by the National Security Archive at George Washington University and posted on the Web today, the 74-page "Information Operations Roadmap" admits that...
11
by: Nemisis | last post by:
Hi everyone, sorry if this post gets really long, i just wanna make sure i fully explain what i am trying to do. I am new to OOP and .net 2.0, so if this is obvious, i am sorry. I have wrote a...
22
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
1
by: mdk7 | last post by:
I am very new to developing forms and queries with Access. The task that I am required to complete is as follows: Build a form based user interface that displays various information from the...
2
by: UofFprogrammer | last post by:
Hello, Several Weeks ago I asked a question about testing for the end of an input file. I have been using this method pretty well for inputting information from an external file. I am using C++. ...
1
by: TaylorLeonard | last post by:
Hi, I have been trying to figure this out for hours, but can't seem to get it. I have a form where the administrator inputs someone elses personal info (FirstName, lastName, email, phone#, etc.) and...
16
by: HypeBeast McStreetwear | last post by:
Hey Guys I have to make a program where it accepts/denies applications into a club. The program should read in information about applicants (None was given so I believe I have to make up some...
0
by: nustapha | last post by:
Hi, I can see foreign keys in the information schema db in mysql but there is no information about 'on delete cascade' or 'on update...'. How can I get all information about foreign keys?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.