471,337 Members | 817 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

DBGrid does not show the content

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
Jan 27 '06 #1
4 1622
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.
--
adi
"Doru Roman" wrote:
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

Jan 27 '06 #2
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.
Jan 27 '06 #3
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

--
adi
"Doru Roman" wrote:
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.

Jan 27 '06 #4
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.
Jan 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ramtin | last post: by
8 posts views Thread by Chad Z. Hower aka Kudzu | last post: by
reply views Thread by basha | last post: by
1 post views Thread by Bill | last post: by
3 posts views Thread by nano9 | last post: by
2 posts views Thread by nano9 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.