on 07-11-2007 8:34 PM
Hey All,
I have a .net user control running on the shipping.aspx page that retrieves the selected address from the drop down list or radio button of addresses in the users account.
This works great for existing addresses and I can save the info.
How can my control know what the address ID is when the user adds a new address? I get the order.GetShippingId it always has the value of the last selected address when adding a new address or 0 which is no good.
Any suggestions on how I can figure out what address ID has been assigned to the new address that was created?
Hi Curtis,
Since my previous suggestions haven't panned out, I guess you can try getting it form the account object or go straight to the DB.
NPBasePage bp = (NPBasePage)Page;
NPAccount a = new NPAccount(bp.AccountID);
// get the last address in the collection
NPAddress address = null;
if (a.Addresses.Count > 0){
address = ((NPAddress)a.Addresses[a.Addresses.Count -1]);
}
if (address != null){
int addressid = address.AddressID;
}
Note that addresses are not sorted in the NPAddress.Addresses query, so it is possible that SQL Server will not return them in order of AddressID. If you are worried about this, you can check the ids to make sure you've got the highest. That will be the one that was just created.
or you could go straight to the DB:
NPBasePage bp = (NPBasePage)Page;
StringBuilder sb = new StringBuilder();
sb.Append("SELECT TOP 1 AddressID ");
sb.Append("FROM UsersAccountAddress ");
sb.Append("WHERE AccountID = @accountid ");
sb.Append("ORDER BY AddressID DESC");
DataParameters dp = new DataParameters(1);
dp.Add(NPDataType.NPInt, "@accountid", bp.AccountID);
object o = DataFunctions.ExecuteScalar(sb.ToString(), bp.Parameters, bp.ConnectionString);
if (o != null){
int addressID = Convert.ToInt32(o);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.