LISTING 1: Using the ExecuteScalar Method to Execute a Query PRIVATE SUB btnInsert_Click(ByVal sender AS System.Object, ByVal e AS System.EventArgs) Handles btnInsert.Click Dim intOrderID AS Integer TRY cn.Open() cmd = New SqlCommand("InsertOrder", cn) WITH cmd .CommandType = CommandType.StoredProcedure WITH .Parameters ' Build parameters collection and set parameter values. .add("@CustomerID", SqlDbType.NVarChar, 5).Value = "HUNGC" .add("@EmployeeID", SqlDbType.Int).Value = 5 .add("@OrderDate", SqlDbType.DateTime).Value = Now .add("@RequiredDate", SqlDbType.DateTime).Value = DateAdd(DateInterval.Day, 5, Now) .add("@ShippedDate", SqlDbType.DateTime).Value = DateAdd(DateInterval.Day, 1, Now) .add("@ShipVia", SqlDbType.Int).Value = 1 ' Shippers .add("@Freight", SqlDbType.Money).Value = 6.5 .add("@ShipName", SqlDbType.NVarChar, 40).Value = "Fred Vaughn" .add("@ShipAddress", SqlDbType.NVarChar, 60).Value = "11223 113th St." .add("@ShipCity", SqlDbType.NVarChar, 15).Value = "Redmond" .add("@ShipRegion", SqlDbType.NVarChar, 15).Value = "WA" .add("@ShipPostalCode", SqlDbType.NVarChar, 15).Value = "98052" .add("@ShipCountry", SqlDbType.NVarChar, 15).Value = "USA" END WITH END WITH ' Stored procedure returns new Order ID. intOrderID = CInt(cmd.ExecuteScalar) txtOrderIDToDelete.Text = intOrderID.ToString CATCH ex AS Exception MsgBox(ex.ToString) ' Report errors to developer. FINALLY cn.Close() ' In any case, close the connection. END TRYy END SUB