I wasn't getting this error before. But now when i try to add any more data, it gives me this error when i try to submit the changes to the database. The complete error is:
c:\Documents and Settings\!rdgupta\Desktop\padrap2_nocms\padrap\pages\admin\addNewPopup.aspx.cs
protected void save_btn_Click_subSite(object sender, EventArgs e)
{
P*********** ndb = new P*********();
//organizationAddress noa = new organizationAddress();
organization norg = new organization();
organizationHierarchy noh = new organizationHierarchy();
int organizationID;
int _addressID = 0;
int.TryParse(hfAddressID.Value, out _addressID);
string _line1 = tbrAddressID1.Text;
string _line2 = tbrAddressID2.Text;
string _line3 = tbrAddressID3.Text;
string _city = tbrCity.Text;
string _stateCode = ddlStateID.SelectedValue;
string _countryISO2 = ddlCountryID.SelectedValue;
string _postalCode = tbrPostalCode.Text;
norg.name = tbNameID.Text;
organizationID = ndb.organizations.Max(c=>c.organizationID) +1;
norg.baseID = organizationID;
norg.organizationID = organizationID;
int temp = this.OrganizationID;
string nqry = string.Format(@"
SELECT org.organizationTypeID
FROM
organization org
WHERE
org.organizationID = {0}
", this.OrganizationID);
norg.organizationTypeID = ndb.ExecuteQuery<int>(nqry).FirstOrDefault();
norg.dateCreated = DateTime.Now;
// norg.createdBy_luserID = 1;
norg.isActive = true;
noh.child_organizationID = organizationID;
noh.parent_organizationID = this.OrganizationID;
if (cbVerify.Checked)
{
JObject jPlacemark = JObject.Parse(ddlVerifySS.SelectedValue);
JsonSerializerSettings jss = new JsonSerializerSettings();
GPlacemark mark = JsonConvert.DeserializeObject<GPlacemark>(ddlVerifySS.SelectedValue, jss);
if (mark != null && mark.AddressDetails != null && mark.AddressDetails.Country != null)
{
GCountry _country = mark.AddressDetails.Country;
_line2 = "";
_line3 = "";
_countryISO2 = _country.CountryNameCode;
if (_country.AdminstrativeArea != null)
{
_stateCode = _country.AdminstrativeArea.AdministrativeAreaName;
GAdministrativeArea _aa = _country.AdminstrativeArea;
if (_aa.SubAdministrativeArea != null && _aa.SubAdministrativeArea != null)
{
GLocality _locality = _aa.SubAdministrativeArea.Locality;
_city = _locality.LocalityName;
_postalCode = _locality.PostalCode.PostalCodeNumber;
if (_locality.Thoroughfare != null)
_line1 = _locality.Thoroughfare.ThoroughfareName;
}
}
}
}
var qry = from a in ndb.addresses
where
(a.addressLine1 == _line1 || string.IsNullOrEmpty(_line1))
&&
(a.addressLine2 == _line2 || string.IsNullOrEmpty(_line2))
&&
(a.addressLine3 == _line3 || string.IsNullOrEmpty(_line3))
&&
(a.city == _city || string.IsNullOrEmpty(_city))
&&
(a.stateCode == _stateCode || string.IsNullOrEmpty(_stateCode))
&&
(a.countryISO2 == _countryISO2 || string.IsNullOrEmpty(_countryISO2))
&&
(a.postalCode == _postalCode || string.IsNullOrEmpty(_postalCode))
select a;
int count = qry.Count();
if (count > 0)
{
address ab = qry.First();
if (ab.addressID.ToString() != hfAddressID.Value) // then it's a different address already in the system
{
hfAddressID.Value = ab.addressID.ToString();
}
}
else // it's new and we need to add it
{
address ab = new address();
if (!string.IsNullOrEmpty(_line1))
ab.addressLine1 = _line1;
if (!string.IsNullOrEmpty(_line2))
ab.addressLine2 = _line2;
if (!string.IsNullOrEmpty(_line3))
ab.addressLine3 = _line3;
if (!string.IsNullOrEmpty(_city))
ab.city = _city;
if (!string.IsNullOrEmpty(_stateCode))
ab.stateCode = _stateCode;
if (!string.IsNullOrEmpty(_countryISO2))
ab.countryISO2 = _countryISO2;
if (!string.IsNullOrEmpty(_postalCode))
ab.postalCode = _postalCode;
ndb.addresses.InsertOnSubmit(ab);
ndb.organizations.InsertOnSubmit(norg);
ndb.organizationHierarchies.InsertOnSubmit(noh);
ndb.SubmitChanges();
hfAddressID.Value = ab.addressID.ToString();
vw_address view = ndb.vw_addresses.SingleOrDefault(add => add.addressID == ab.addressID);
var responseJSON = GGeocode.GetLocation(view.address);
JObject obj = JObject.Parse(responseJSON);
}
ndb.Dispose();
Server.Transfer("********.aspx", false);
}
Can somebody explain to me why I started getting this error and how to solve it.
Thanks.