Hi Ramchandran,
1) When fetching from service you are getting a colllection from the database and binding that to your listbox
2) When saving the data to your database you are only saving the data. If you can call the method which returns a collection while saving the data that will update the listbox without refreshing the page. Please have a look at the sample code below.
-- Fetch Data
public ObservableCollection<Customer> GetData()
{
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand cmd = new SqlCommand("select * from Persons", conn))
{
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
cust = new ObservableCollection<Customer>();
while (dr.Read())
{
Customer c = new Customer();
cust.Add(c);
}
}
}
return cust;
}
-- Save Data
public ObservableCollection<Customer> Save(Customer input)
{
using (SqlConnection conn = new SqlConnection(connString))
{
string insert = "insert into Persons values (" + input.id + ",'" + input.lname + "','" + input.fname + "','" + input.city + "')";
using (SqlCommand cmd = new SqlCommand(insert, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}
return GetData();
}