Hi Everyone,
I have two list boxes - lstBusinesses and lstBusinessDetails. When the business name in lstBusinesses is selected I want to run a query to the database that will select all the associated information from this business name which is done by passing a parameter with the value of the selected item in lstBusinesses and display the result information in lstBusinessDetails.
Here is my code but when I debug it, it seems to be skipping the reader part where i write information to the lstBusinessDetails.
This is fired when the OnSelectedIndexChanged event is initiated in lstBusinesses
protected void ShowBusinessDetails(object sender, EventArgs e)
{
SqlConnection conn;
SqlCommand comm;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
String connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
conn = new SqlConnection(connectionString);
conn.Open();
comm = new SqlCommand("SELECT Address_Line_1, Address_Line_2, Address_Line_3, Provence, County, Telephone from Business WHERE Business_Name=@BusinessName", conn);
comm.Parameters.Add("@BusinessName", System.Data.SqlDbType.VarChar).Value = lstBusinesses.SelectedIndex.ToString();
SqlDataReader reader = comm.ExecuteReader();
while(reader.Read())
{
String AddressLine1 = reader.GetString(3);
lstBusinesses.Items.Add(AddressLine1);
String AddressLine2 = reader.GetString(4);
lstBusinesses.Items.Add(AddressLine2);
String AddressLine3 = reader.GetString(5);
lstBusinesses.Items.Add(AddressLine3);
String County = reader.GetString(6);
lstBusinesses.Items.Add(County);
String Provence = reader.GetString(7);
lstBusinesses.Items.Add(Provence);
String Owner = reader.GetString(8);
lstBusinesses.Items.Add(Owner);
String Telephone = reader.GetString(10);
lstBusinesses.Items.Add(AddressLine1);
}
}
Also is it possible in the one query to select information also from another table? I have a table User_Acc which has an email address for the business that I would also like to display in lstBusinessDetails...