I am having some nullreference error and i can't spot why, this is my entire function where im getting the error, the red highlight is where the error occurs
private void unidadesBtn_Click(object sender, EventArgs e)
{
var owner_response = proxy.GetOwners();
if (owner_response != null)
{
DataTable vehicleData = new DataTable();
foreach (var owner in owner_response.Owners)
{
var vehicle_response = proxy.GetVehicles(owner.OwnerId);
if (vehicle_response != null)
{
vehicleData.Columns.Add("TypeDisplayName", typeof(SqlString));
vehicleData.Columns.Add("DefaultDriverId", typeof(Guid));
vehicleData.Columns.Add("VehicleId", typeof(Guid));
vehicleData.Columns.Add("OwnerId", typeof(Guid));
vehicleData.Columns.Add("DisplayName", typeof(SqlString));
vehicleData.Columns.Add("Description", typeof(SqlString));
vehicleData.Columns.Add("Registration", typeof(SqlString));
vehicleData.Columns.Add("Notes", typeof(SqlString));
vehicleData.Columns.Add("VehicleTypeId", typeof(Guid));
vehicleData.Columns.Add("VehicleProfileId", typeof(Guid));
vehicleData.Columns.Add("NotifyDriverOfGeofenceAlert", typeof(Boolean));
vehicleData.Columns.Add("IsProfile", typeof(Boolean));
vehicleData.Columns.Add("VehicleGroupId", typeof(Guid));
vehicleData.Columns.Add("CreatedDateTime", typeof(DateTime));
vehicleData.Columns.Add("ModifiedDateTime", typeof(DateTime));
vehicleData.Columns.Add("UserId", typeof(Guid));
vehicleData.Columns.Add("UniqueVehicleId", typeof(SqlString));
vehicleData.Columns.Add("DefaultVechileStateId", typeof(Boolean));
vehicleData.Columns.Add("GISCulture", typeof(SqlString));
foreach (var vehicle in vehicle_response.Vehicles)
{
vehicleData.Rows.Add(vehicle.TypeDisplayName.ToCharArray(), vehicle.DefaultDriverId, vehicle.VehicleId, vehicle.OwnerId,
vehicle.DisplayName.ToCharArray(), vehicle.Description.ToCharArray(), vehicle.Registration.ToCharArray(), vehicle.Notes.ToCharArray(),
vehicle.VehicleTypeId, vehicle.VehicleProfileId, vehicle.NotifyDriverOfGeofenceAlert, vehicle.IsProfile, vehicle.VehicleGroupId,
vehicle.CreatedDateTime, vehicle.ModifiedDateTime, vehicle.UserId, vehicle.UniqueVehicleID.ToCharArray(),
vehicle.DefaultVehicleStateID, vehicle.GISCulture.ToCharArray());
}
string nombre = owner.OwnerName;
}
}
if (vehicleData.Rows.Count > 0)
{
SqlConnection con = new SqlConnection(@"Data Source=10.113.192.122\SQLEXPRESS;Initial Catalog=FOO;Persist Security Info=True;User ID=Navman;Password=Pato745477;Initial Catalog=Navman");
SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock);
bc.DestinationTableName = "Vehicles";
bc.BatchSize = vehicleData.Rows.Count;
con.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM dbo.Vehicles");
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
cmd.ExecuteNonQuery();
bc.WriteToServer(vehicleData);
bc.Close();
con.Close();
}
}
}