What is the correct syntax to insert a data in a table that has a foreign key.
I need to insert information in Purchase Details
table but the column name PurchaseNo
is a foreign key to the Purchases
table. This is my database:
Purchase Details:
- RefNo (PRIMARY KEY, UNIQUE)
- PurchaseNo (FOREIGN KEY)
- ProductID (FOREIGN KEY)
- Quantity
Purchases:
- PurchaseNo (PRIMARY KEY, UNIQUE)
- SupplierID (FOREIGN KEY)
- DatePurchased
- DateReceived
- ReceiptNo
- Status
This is my goal:
my syntax code behind is:
using (SqlConnection con = new SqlConnection(kb.GetConnection()))
{
con.Open();
string query = @"INSERT INTO PurchaseDetails VALUES (@PurchaseNo, @ProductID, @Quantity)"
}