DBGrid does not show the content

D

Doru Roman

Hi,

I write some code to retrieve information from Database.
After I bind the DBGrid it shows the result somehow like a link to the
Table.
When I click on the Table link it displays the whole content. It probably
has
to do with parent-child relationship, but I only have one result set.
Here is the code that accesses Northwind database:

SqlConnection conn = new SqlConnection("data source=YOUR-136F2019DC;initial
catalog=Northwind;password=mypassword;persist security info=True;user
id=sa;workstation id=YOUR-136F2019DC;packet size=4096");

conn.Open();



SqlCommand cmd1 = conn.CreateCommand();

cmd1.CommandText = "Select top 100 * from Customers";

cmd1.CommandType = CommandType.Text;

SqlCommand cmdCust = conn.CreateCommand();

cmdCust.CommandText = "Select top 100 * from Customers";

cmdCust.CommandType = CommandType.Text;

SqlDataAdapter daCust = new SqlDataAdapter(cmdCust);

DataSet dsCust = new DataSet();

daCust.Fill(dsCust);

dgCust.DataSource = dsCust;

dgCust.Expand(-1);

conn.Close();



It's probably some setting I am not aware of.

Thanks,

Doru
 
G

Guest

Why are you using 2 command to call the same SQL? (Hope you are not Filling
the DataSet twice on a child table?)
But that should not affect the datagrid, I would check your DG, because if
you say you see a link, then it might be that in a column setting. Also check
how you are binding the DataSet to the DG.
 
D

Doru Roman

Thanks for the reply.
When I cut the sample I forgot to take out the first command which does not
influence the grid.
Aside from the code I do not set anything else for the grid. It first shows
a one column with a +
sign in the checkbox(the collapse sign) which has a line that connects to a
text box in which there is a link
with "Table" as text. When I click inside the text box on the Table link,
then the grid shows the whole
content of the query. On the sleeve of the grid a left arrow shows which has
this caption:
"Navigate back to the parent row". It's like it consider the result of the
query as a child recordset and I don't
know why.
The only way I bind the grid is through code.
 
G

Guest

Seems like a pre-designed grid. I did use this type of DG a while ago, and
all the settings were made from the HTML view of the Grid. You may want to
first view the DG in deisgn view and then go to its properties to see where
are those '+' signs and the link that says 'Navigate...' I bet there is also
a relation specified in the HTML code.

HTH
 
D

Doru Roman

It doesn't matter whether I use a grid control from the toolbox or I create
it by code, it behaves the same.
Please try the code I provided to see if you get a different display.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top