I do not view what I need in my Datagrid

Hello,
here is my code, It is very simple, only one table, I want to show the table content in the Datagrid.
It currently works, but I need to click on a "+" sign, then, the word "table" and then I got my "item table" and the content.

How come?  My       dataGrid1.DataMember is Setted.

How to I get only the table content to be displayed?

Thanks!




                  string _myConnStr = "Data Source=eb.mdb;Provider=Microsoft.Jet.OLEDB.4.0;";
                  string _mysqlstr = "SELECT * FROM item ORDER BY ordernum";
                        try
                        {
                              myOledbConn = new OleDbConnection(_myConnStr);
                              myOledbConn.Open();
                              Console.WriteLine("\nmyOledbConn Open...");
                        }
                        catch(Exception ex)
                        {
                              MessageBox.Show("Error: Failed to create a database connection. \n{0}" + ex.Message);
                              Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
                              return;
                        }

                  selectCMD = new OleDbCommand(_mysqlstr,myOledbConn);
                  myitemDA = new OleDbDataAdapter(selectCMD);
                  myitemDS = new DataSet();
                  myOledbConn.Close();
                  Console.WriteLine("Dataset errors?: " + myitemDS.HasErrors);
                  dataGrid1.DataMember = "item";
                  dataGrid1.DataSource = myitemDS;
                  myitemDS.Clear();
                  myitemDA.Fill(myitemDS);                  
            }
Yann de ChamplainAssociateAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TonylmillerCommented:
I normally do it like this:

DataSet GridDS = BuildGridDataSet(); //This method fills the table with data.
dataGrid1.SetDataBinding(GridDS, "TableName");

I normally build my dataset before binding, as you can see.                  

If that doesn't work, look at your dataset.  Maybe something strange is going on.  From what you have said, it looks like you might have a parent/child relationship going in there.

I use a method to print all table contents to the console, which helps in debugging (unless your table has too many rows).

Of course, you can always set your tablestyle and columstyles to get exactly what you want in your datagrid.

Good luck!
0
Yann de ChamplainAssociateAuthor Commented:
Do you mean you put your OleDbDataAdapter and Fill in your method and return the dataset?

               selectCMD = new OleDbCommand(_mysqlstr,myOledbConn);
               myitemDA = new OleDbDataAdapter(selectCMD);
               myitemDS = new DataSet();
When I change the code I many times get:
Additional information: Cannot create a child list for field item.

My code id now:

                  string _myConnStr = "Data Source=eb.mdb;Provider=Microsoft.Jet.OLEDB.4.0;";
                  string _mysqlstr = "SELECT caption, url FROM item";
                        try
                        {
                              myOledbConn = new OleDbConnection(_myConnStr);
                              myOledbConn.Open();
                              Console.WriteLine("\nmyOledbConn Open...");
                        }
                        catch(Exception ex)
                        {
                              MessageBox.Show("Error: Failed to create a database connection. \n{0}" + ex.Message);
                              Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
                              return;
                        }

                  myitemDA = new OleDbDataAdapter(_mysqlstr,myOledbConn);
                  myitemDS = new DataSet();
                  myitemDA.Fill(myitemDS);
                  dataGrid1.SetDataBinding(myitemDS, "item");
0
TheAvengerCommented:
You should set the DataMember to the name of the table, namely "ORDER", not "item"
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

TonylmillerCommented:
Good point.  I had assumed that "item" was the name of the table.  

It should look just like my example:

dataGrid1.SetDataBinding(GridDS, "TableName");

with the name of the dataset and then the name of the table in double quotes.
0
Yann de ChamplainAssociateAuthor Commented:
item is the table name.
0
TheAvengerCommented:
Based on your code it's ORDER, not item. Change it and see
0
TheAvengerCommented:
I mean your original code
0
Yann de ChamplainAssociateAuthor Commented:
The only place where ORDER is written is the ORDER BY of the select statement.

Her is a new version of my code without any order by:

string _myConnStr = "Data Source=eb.mdb;Provider=Microsoft.Jet.OLEDB.4.0;";
                  string _mysqlstr = "SELECT caption, url FROM item";
                        try
                        {
                              myOledbConn = new OleDbConnection(_myConnStr);
                              myOledbConn.Open();
                              Console.WriteLine("\nmyOledbConn Open...");
                        }
                        catch(Exception ex)
                        {
                              MessageBox.Show("Error: Failed to create a database connection. \n{0}" + ex.Message);
                              Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
                              return;
                        }
                  myitemDA = new OleDbDataAdapter(_mysqlstr,myOledbConn);
                  myitemDS = new DataSet();
                  myitemDA.Fill(myitemDS);
                  dataGrid1.SetDataBinding(myitemDS, "item");// to change the Datasource and Dataqmember at run time.
0
TheAvengerCommented:
OK, sorry, my mistake :-((

By the way: you don't need to open or close the connection. The data adapter will do this alone. Try this code:

string _myConnStr = "Data Source=eb.mdb;Provider=Microsoft.Jet.OLEDB.4.0;";
string _mysqlstr = "SELECT caption, url FROM item";
myOledbConn = new OleDbConnection(_myConnStr);
myitemDA = new OleDbDataAdapter(_mysqlstr,myOledbConn);
myitemDS = new DataSet();
myitemDA.Fill(myitemDS);
dataGrid1.DataMember = myitemDS.Tables[0].TableName;
dataGrid1.DataSource = myitemDS;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TonylmillerCommented:
Not sure if it will create the "item" table for you in your dataset automatically.

Try this:

Create a dataset that contains the item table.  Let's say its called ItemDataSet.xsd

Then do myitemDS = new ItemDataSet(); //in place of your code.

Let me know if it works.  :-)
0
Yann de ChamplainAssociateAuthor Commented:
TheAvenger your code works perfectly.

But, I don't undersand why... since it looks same a my code.

The only diff. is myitemDS.Tables[0].TableName;

Does that mean, the code might have a problem with "item"?
0
TheAvengerCommented:
No, maybe because of the table name. Try to print the table name:

MessageBox.Show (myitemDS.Tables[0].TableName);

and have a look what it is
0
Yann de ChamplainAssociateAuthor Commented:
Great idea...
With a very unpredictable result for me!

The table name is... "Table"!!!

I guest this is because the dataset is filled automatically?
0
TheAvengerCommented:
Probably, yes :-(( I didn't know that
0
Yann de ChamplainAssociateAuthor Commented:
I would like to give points to both of you.
I am not sure how to achieve that.
Do you know how?
0
TheAvengerCommented:
You should have a link called Split Points, below the messages I believe. Then you can decide to whom to give how many points and who is the accepted answer and who is assisted answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.