No data in DataGrid

W

Werner

I am having trouble getting my data into the datagrid.
All I get is the header row.
What am I doing wrong?

Or is there a problem with the new service packs?

Here is my source code:

DbConnection db = new DbConnection(conString,DbTypEnum.SQL_Server_Typ);
SuperDataAdapter adapLogs = db.CreateDataAdapter("Select * from LogEintrag");

DataSet dsLogs = new DataSet();

db.Open();

adapLogs.Fill(dsLogs,"LogEintrag");

DataGrid1.DataSource = dsLogs;
DataGrid1.DataMember = "LogEintrag";
DataGrid1.DataBind();
db.Close();

Nice regards
Werner Kratochwil
 
A

Alvin Bruney [MVP]

put this code before you bind
if(dsLogs != null && dsLogs.Tables.Count > 0 && dsLogs.Tables[0].Rows.Count
bind
else
no data

in fact, you always need that if check to guarantee that IListsource
interface doesn't throw an exception on null data.
 
W

Werner

Hi Alvin!

Maybe you got my question wrong.
The problem is not that there is no data - but somehow the transfer
from the DataSet to the DataGrid does not work.
I just checked: I got more than 300 rows in the dataset - still only
the header row is displayed.
And I got no idea why.
There is no exception or any other kind of error message.

Nice regards
Werner

Alvin Bruney said:
put this code before you bind
if(dsLogs != null && dsLogs.Tables.Count > 0 && dsLogs.Tables[0].Rows.Count
bind
else
no data

in fact, you always need that if check to guarantee that IListsource
interface doesn't throw an exception on null data.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Werner said:
I am having trouble getting my data into the datagrid.
All I get is the header row.
What am I doing wrong?

Or is there a problem with the new service packs?

Here is my source code:

DbConnection db = new DbConnection(conString,DbTypEnum.SQL_Server_Typ);
SuperDataAdapter adapLogs = db.CreateDataAdapter("Select * from
LogEintrag");

DataSet dsLogs = new DataSet();

db.Open();

adapLogs.Fill(dsLogs,"LogEintrag");

DataGrid1.DataSource = dsLogs;
DataGrid1.DataMember = "LogEintrag";
DataGrid1.DataBind();
db.Close();

Nice regards
Werner Kratochwil
 
W

Werner

OK. I have found the error myself:

Rewriting the DataSource property is not possible.
If you set it once (for example to a typed dataset in the designer) -
it just ignores, if you reset it before doing the databind.
I populated the other dataset, thinking that it would consider it.
So, if you want to use any other dataset, never set the DataSource
property.

Would be helpful to get an error message, when trying to reset the
DataSource property to inform about this "feature" ;-)

Sorry about being sarcastic, but it took me a whole day to find this
out -aaaarggh

What would I do if I decided I want to load another table at runtime?
Well the SetDataBinding method would do that - I just found that in
the description of DataGrid.DataSource.
I hope Microsoft has a good reason for making things so complicated
-sometimes.

Hope this posts helps others to save a day of searching.
Nice regards
Werner
 

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

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top