Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:07:15+00:00 2026-06-13T18:07:15+00:00

The following code (exactly the same) is running fine on another project. private void

  • 0

The following code (exactly the same) is running fine on another project.

 private void AddComboBoxCells()
        {
            DataGridViewComboBoxCell dgvcell;
            _query = "select ProductName from Product";
                com = new SqlCommand(_query, con);
                    for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                    {
                        dgvcell = new DataGridViewComboBoxCell();
                        dataGridView1[1, i] = dgvcell;
                        myrdr = com.ExecuteReader();
                        while (myrdr.Read())
                        {
                            dgvcell.Items.Add(myrdr.GetValue(0));
                        }
                        myrdr.Close();
                    }

        }

On this project currently i am trying to run this same code but i am getting following error at runtime:

enter image description here

What i am doing is i am pulling records i.e. product names and populating it in the second column of the datagridviewcomboboxcell.

EDIT

 private void btnAdd_Click(object sender, EventArgs e)
    {
        DataRow dtr = tblOrders.NewRow();
        tblOrders.Rows.Add(dtr);
        DataGridViewComboBoxCell dgvcell;
        _query = "select * from Product";
        com = new SqlCommand(_query, con);
            dgvcell = new DataGridViewComboBoxCell();
            dataGridView1[1, dataGridView1 .Rows.Count -2 ] = dgvcell;
            myrdr = com.ExecuteReader();
            while (myrdr.Read())
            {
                dgvcell.Items.Add(myrdr[0]);
            }
            myrdr.Close();
    }

This Add button Code works hence the Data coming in is valid for sure. Please assist.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:07:16+00:00Added an answer on June 13, 2026 at 6:07 pm

    First of all you may want to attach a handler to the DataError event of the DataGridView control to get access to more information about the error you are getting.

    Second, the obvious things to check are the data context that you’re using in the second project. It seems very likely that it is not a programming error necessarily but more like an issue that is related to the underlying data that you are querying and/or doing data binding against.

    You may want to investigate the type of data and the values that are returned by your query: select ProductName from Product.

    Look at myrdr.getValue(0) – rewrite the line dgvcell.Items.Add(myrdr.GetValue(0)); like this:

    object val = myrdr.GetValue(0);  
    dgvcell.Items.Add(val);         // put a break-point here and check val
    

    EDIT

    To answer your question regarding how to handle the DataError event, all you need to do is simply attach a handler to the event member of your ‘dataGridView1’ object (if you don’t know what events are, or how to attach handlers to events in C# then I suggest you do some reading about that online – there are tons of resources everywhere)

    // you will want to add this code to attach the handler in your initialization code - maybe in the Load event handler
    dataGridView1.DataError += new DataGridViewDataErrorEventHandler(DataGridView1);
    
    // ....
    
    // an then define this function somewhere in your class to handle the event
    private void DataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs anError)
    {
         // this function will be called when an error occurs.
         //  you can then use the anError paramenter to get insight into the type and cause of the error
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following three pieces of code behave exactly the same: <p {padding: 0 15
I've read the following post. My Code looks exactly the same, but does not
I am getting the following error when running my code: Typeerror: lambda() takes exactly
I have the following code in netbeans (using javafx in the same project): public
Take the following code snippet: SPAttachmentCollection attachments = item.Attachments ; What exactly is SPAttachmentCollection
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
I have the following code in PHP, I am trying to write the same
I have the following declarative js/dojo code running properly in Chrome: <div dojoType=dijit.form.TextBox> <script
I am running the following code: if(ven.Source == null)ven.Source = new Source(); ven.name =
I have many functions on a page, where the following code is exactly the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.