Reputation: 41
Im retriving data from a database displayed on a dropdownlist. The dropdown display the streetname along with the number of the house. An example from my data is: "Streetname 44". Now when the data isretrived and displayed on the dropdown, I want to save the data into another table in the database, but this time i want the "Streetname" to be on the "street-column" and the "44" stored in the "number-column". Im using LINQ to store my data and so far I have this:
using (DB_Entities tt = new DB_Entities())
{
Address va = new Address();
va.Street = ListItemStreet.SelectedItem; // I only want the Strings from the itemlist
va.HouseNo = ListItemStreet.SelectedItem; // I only want the number from the itemlist
tt.ValidateAddress.AddObject(va);
tt.SaveChanges();
if (tt != null)
{
AddError.Text = "Saved!";
}
else
{
AddError.Text = "Error";
}
}
EDIT: It's not a textbox but a Itemlist were the street is retrieved
Upvotes: 0
Views: 204
Reputation: 75306
You can parse like this:
string address = "Streetname 44";
var index = address.LastIndexOf(' ');
var houseNo = address.Substring(index + 1);
var streetName = address.Remove(index);
Upvotes: 1