databind to a DataSet

I'm trying to bind to a dataset, but am getting an exception that a field does not exist, which should.  My method to create the DataSet  is below (in its infancy).  It's VERY simple.  Here is the databinding:

DataSet result = this.getDataSet(fields);
dataGridView1.DataSource = result.Tables["main"];


cbc0 = new DataGridViewComboBoxColumn();
           
cbc0.DisplayIndex = 0;
cbc0.DataSource = result.Tables["createOptions"];
cbc0.DisplayMember = "text";  ///////////////////////////////PROBLEM - text field not found!
cbc0.ValueMember = "id";
dataGridView1.Columns.Add(cbc0);



DataSet creation code:  


        private DataSet getDataSet(ComboBox cb) {
            DataSet result = new DataSet();

            DataTable dt = new DataTable("main");
            DataColumn dc = new DataColumn("AttributeName", Type.GetType("System.String"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dbField", Type.GetType("System.String"));
            dt.Columns.Add(dc);
            dc = new DataColumn("create", Type.GetType("System.Int32"));
            dt.Columns.Add(dc);

            DataRow row;
            for (int i = 0; i < cb.Items.Count; i++) {
                row = dt.NewRow();

                cb.SelectedIndex = i;
                row["AttributeName"] = cb.SelectedValue.ToString();
                row["dbField"] = cb.SelectedValue.ToString();
                row["create"] = 0;
                dt.Rows.Add(row);
            }

            result.Tables.Add(dt);

            dt = new DataTable("createOptions");
            dc = new DataColumn("id", Type.GetType("System.Int32"));
            dt.Columns.Add(dc);
            dc = new DataColumn("text", Type.GetType("System.String"));
            dt.Columns.Add(dc);

            row = dt.NewRow();
            row["id"] = 0;
            row["text"] = "Create";
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["id"] = 1;
            row["text"] = "Don't Create";
            dt.Rows.Add(row);

            result.Tables.Add(dt);

            return result;
        }
ARACK04Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Harland GomezSoftware Engineer IICommented:
Have you tried renaming the column name? maybe the text is a reserved word.. just a thought..
e1vCommented:
Hello, I tried to run your code using a databound combobox as the parameter in the DataSet result = this.getDataSet(fields);
and it compiled an ran without errors...So I'm not sure what the problem is...

I can give you one general tip, always set DisplayMember and ValueMember before you set DataSource
http://blogs.msdn.com/subhagpo/archive/2005/02/17/375112.aspx

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
ARACK04Author Commented:
I moved the datasource line after the valuemember and DisplayMember, and renamed text to text2, but it's still not finding it.  This is weird.
ARACK04Author Commented:
Thanks guys.  I went in a different directiosn, got it to work, then went backwards to what I had originally, and it still works; I am unable to re-create the error.  Well, thanks for the help!!!!
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.