Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
to show data from database in datagridview i code this

string p_code = P1.Text;
string p_design = P2.Text;
SqlDataAdapter pgrid = new SqlDataAdapter("Select * From Product Where Item_Code = @p_code OR Design = @p_design", connection_v);
pgrid.SelectCommand.Parameters.AddWithValue("@p_code", @p_code);
pgrid.SelectCommand.Parameters.AddWithValue("@p_design", @p_design);
DataTable pt = new DataTable();
pgrid.Fill(pt);
dgv_p.DataSource = pt;


this is working fine n its output is like this
Item Code Design ...........
55555 RM-5

but i want output like this
Item Code 55555
Design RM-5
.
.
Posted

1 solution

I do not think there is s straight fwd way to do it. One of the easy ways is to:

1. Get the data as you are doing it
2. Transpose the data in the datatable
3. Insert first column with the column names
4. Set the appropriate cell style for first column so it looks like header
5. Hide actual heade of datagridview.
 
Share this answer
 

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