Two table inserts retaining same ID for a ForeignKey using Webmatrix, Bootstrap, Html, and SQL

38 Views Asked by At

I am working in visual studio with a database that has many tables. I have a html bootstrap form which allows a user to input various fields and those fields must be inserted back into my database.

The insert statements work but not as expected. When I run "SELECT * From Storage FULL OUTER JOIN Cars ON Storage.carID = Car.carID". It shows two rows. One row has all NULL values for car except for carID/Name/Model and storage is the exact opposite.

I've tried playing around with a few ideas including webmatrix's GetLastInsertID() function but no luck. I'm a novice at this. Any help would be great!

See insert statements below...

@{
  var db = Database.Open("DB Name");

  if (IsPost)
  {
      var inSql = "INSERT INTO Storage (location, GPS) VALUES (@0, @1)";

      var data = db.QueryValue(inSql,
              Request.Form["location"],
              Request.Form["gps"],

      var inCarSql = "INSERT INTO Cars (carName, modelName) VALUES (@0, @1)";

          var bData = db.QueryValue(inCarSql,
              Request.Form["carName"],
              Request.Form["modelName"]);           
  }
}

0

There are 0 best solutions below