First of all I tried this Insert Data Into Tables Linked by Foreign Key and didn't get the answer.
I have 3 tables:
Table: Customers
ID -------LastName-------FirstName-------PhoneNumber
Table: Order
ID-------Status-------CustomerID
Table: OrderLine
ID-------OrderID-------Product-------Quantity-------PricePerUnit
I run the following query
SqlCommand myCommand2 =
new SqlCommand(@"INSERT INTO Order (Status, CustomerID)
VALUES(13016, SELECT ID FROM Customers WHERE FirstName = 'Garderp')",
myConnection);`
and it throws exception
Syntax error near Order
How can I add data into table with foreign key in SQL Server 2008 especially in this particular case?