Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have one repeater and 2 tables, and I want to eval the two tabels at the same time but without melting them together.

Could I do it in the codebehind, when I bind the data to the repeater??

C#
SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = @"SELECT * FROM frugt??? Can I have 2 select here?
 
ORDER BY Type";

            conn.Open();
            DataTable visProdukter = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            adapter.Fill(visProdukter);
            cmd.ExecuteNonQuery();
            conn.Close();
            VisProdukt.DataSource = visProdukter;
            VisProdukt.DataBind();


/Tina
Posted

I Suggest to change repeater's header to general name for fruit and vegetable
like productid, produtname, varedi
then your select statement will be:
SQL
SELECT  frugt_id AS Product_id, frugt_navn AS ProductName, vaerdi AS vaerdi, FROM frugt UNION SELECT groent_id AS ProductID, groent_navn AS ProductName, groent_vaerdi AS Varedi FROM groent

then you will not have 0 value in your repeater.
Hope it helps
 
Share this answer
 
Comments
tina_overgaard 18-Oct-13 15:29pm    
Thank you very much for your help
Mehdy Moini 18-Oct-13 16:02pm    
Welcome
Yes. It is possible to write two select statements using DataReader and DataAdapter

Refer here for more details,
Executing multiple SQL statements as one against SQL Server[^]
 
Share this answer
 
Comments
tina_overgaard 18-Oct-13 7:35am    
I cannot use the datatable??
Thomas ktg 18-Oct-13 7:42am    
How do you want it to be done then?
tina_overgaard 18-Oct-13 11:09am    
I want to use the repeater that I know.
I have to get this SELECT * FROM frugt and SELECT * FROM groent inside the same repeater is that possible? I really hope so or else I have a problem
Mehdy Moini 18-Oct-13 8:27am    
VisProdukt is a grid with two table?
tina_overgaard 18-Oct-13 9:52am    
It is a repeater with to tables. The one is fruits and the another one is vegetables.

You can only choose 14 fruits and only 7 vegetables. Therefor I need both textbox to get the user information in a session to another page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900