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 6028423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:44:15+00:00 2026-05-23T04:44:15+00:00

just got a slight problem here with updating a MySql DataGridView from visual studio

  • 0

just got a slight problem here with updating a MySql DataGridView from visual studio in C#. The code below contains the fillData(); method that populates the datagrid. The Exception error is thrown in the button code. The aim of the button is to replace the Reviewed field from 0 to 1, meaning that the reviewed checkbox is then selected. This is probably a very basic problem so i may ask more questions, hope you can help.

public DataTable tb = new DataTable();
public MySqlDataAdapter a = new MySqlDataAdapter();

public void fillData()
{
    using (MySqlConnection c = new MySqlConnection("host="";user="";password=""; database="";"))
    {
        c.Open();                
        string strSQL = "SELECT DataID, Date, WhichMeal, HbA1C_Test, Carbohydrates, GlucoseReading, InsulinUsed, InsulinType, ReviewedBy, Reviewed From PatientData WHERE username = '" + uname.Text + "';";

        using (MySqlDataAdapter a = new MySqlDataAdapter(strSQL, c))
        {
            a.Fill(tb);
            dataGridView2.DataSource = tb;
        }


private void button5_Click(object sender, EventArgs e)
{
    using (MySqlConnection c = new MySqlConnection("host=;user=;password= ""; database=""))
    {
        try
        {
            string DataId =  dataGridView2.Rows[this.dataGridView2.SelectedRows[0].Index].Cells["DataID"].Value.ToString();
            string Update = string.Format("UPDATE PatientData SET Reviewed = 1 WHERE DataID = {0}", DataId);
            MySqlCommand command = new MySqlCommand(Update, c);

            c.Open();
            command.ExecuteNonQuery();
            c.Close();
            tb.Clear();
            fillData();
        }
        catch (MySqlException ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
}
  • 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-05-23T04:44:16+00:00Added an answer on May 23, 2026 at 4:44 am

    You can find the problem, by checking the following things:

    • How many entries are there in
      this.dataGridView2.SelectedRows?
    • How many entries are there in this.dataGridView2.Rows?
    • What is the value of this.dataGridView2.SelectedRows[0].Index?

    Index value is greater than the valid number of entries in one of those collecions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just got a request from my boss for an application I'm working on. Basically
I just got a dedicated server from a hosting company, and for some reason,
I just got through manually removing the bin\ and obj\ folders from around 30
I just got my azure invitation code...yay! Are there any official samples for windows
I just got this error message: ... from c:/ruby/lib/ruby/gems/1.8/gems/... ... 10 levels... from c:/ruby/lib/ruby/gems/1.8/gems/...
I just got rejected on my Free app from app store. I uploaded 3
How could this be happening? sqlite> select read, text from message; 1|No just got
I just got a mail from my DB adminstrator with these details The environment
Just got a question about generics, why doesn't this compile when using a generic
I just got Delphi 2009 and have previously read some articles about modifications that

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.