private void BindList() { string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString; OracleConnection conn = new OracleConnection(); conn.ConnectionString = connectionString; OracleCommand comm = conn.CreateCommand(); comm.CommandText = "select distinct u.name submitter,r.recipeid id, r.recipename recipe, c.type category, ig.name ingredient from recipes r left join users u on r.userid = u.userid left join categories c on r.categoryid = c.categoryid left join recipeslinkingredients i on r.recipeid = i.recipeid left join ingredients ig on ig.ingredientid = i.ingredientid where "; comm.CommandText += submitList.SelectedItem.Value.Equals("0") ? "1=1" : "u.userid = " + submitList.SelectedItem.Value; comm.CommandText += categoryList.SelectedItem.Value.Equals("0") ? " and 1=1" : " and r.categoryid = " + categoryList.SelectedItem.Value; comm.CommandText += ingredientList.SelectedItem.Value.Equals("0") ? " and 1=1" : " and i.ingredientid = " + ingredientList.SelectedItem.Value; comm.CommandType = CommandType.Text; DataTable table; table = new DataTable(); try { comm.Connection.Open(); OracleDataReader reader = comm.ExecuteReader(); table.Load(reader); } catch (SqlException ex) { exception.Text = ex.Message; } catch (Exception ex) { exception.Text = ex.Message; } finally { comm.Connection.Close(); } GridViewRecipe.DataSource = table; GridViewRecipe.DataBind(); }
private void BindList() { string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString; OracleConnection conn = new OracleConnection(); conn.ConnectionString = connectionString; OracleCommand comm = conn.CreateCommand(); comm.CommandText = "select c.type, r.recipeid,r.recipename,r.categoryid, u.name from categories c join recipes r on c.categoryid = r.categoryid join users u on r.userid = u.userid"; comm.CommandType = CommandType.Text; DataTable table; table = new DataTable(); try { comm.Connection.Open(); OracleDataReader reader = comm.ExecuteReader(); table.Load(reader); } catch (SqlException ex) { exception.Text = ex.Message; } catch (Exception ex) { exception.Text = ex.Message; } finally { comm.Connection.Close(); } GridViewRecipe.DataSource = table; GridViewRecipe.DataBind(); }