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

  • Home
  • SEARCH
  • 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 6900457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:32:55+00:00 2026-05-27T07:32:55+00:00

Hello I’m having a problem here. The code looks like this. private void Form3_Load(object

  • 0

Hello I’m having a problem here. The code looks like this.

private void Form3_Load(object sender, EventArgs e)
{ 
     string connectionString =
     "Server=localhost;" +
     "Database=oroderm;" +
     "User ID=root;" +
     "Password=root;" +
     "Pooling=false";
     string query = "Select * from client";
     MySqlConnection conn = new MySqlConnection(connectionString);
     MySqlDataAdapter dAdapter = new MySqlDataAdapter(query, connectionString);
     conn.Open();
     DataSet ds = new DataSet();
     MySqlCommandBuilder cBuilder = new MySqlCommandBuilder(dAdapter);

     dAdapter.Fill(ds, "client");

     BindingSource bSource = new BindingSource();
     bSource.DataSource = ds.Tables["client"];
     dataGridView2.DataSource = bSource;
}

private void button1_Click(object sender, EventArgs e)
{
     DataTable dt = ds.Tables["client"];
     this.dataGridView2.BindingContext[dt].EndCurrentEdit();
     this.da.Update(dt);
}

So what I want is that whenever I edit the values in my Datagrid it will affect my database after I click button1 (save button). ex. If I have roman as the client after I changed his name and I click button1 it should change. However Im getting a value cannot be null error. Please can somebody help. T_T

*EDIT: Heres the Updated Code

private MySqlDataAdapter _da;
        private DataTable _dt;
        private DataSet _ds;

 private void Form3_Load(object sender, EventArgs e)
        {
               updateClient();
        }

public void updateClient()
        {
            string connectionString =
             "Server=localhost;" +
             "Database=oroderm;" +
             "User ID=root;" +
             "Password=root;" +
             "Pooling=false";

            string query = "select * from client";
            MySqlConnection conn = new MySqlConnection(connectionString);
            _da = new MySqlDataAdapter(query, connectionString);
            conn.Open();
            _ds = new DataSet();
            MySqlCommandBuilder cBuilder = new MySqlCommandBuilder(_da);

            _da.Fill(_ds, "client");
            BindingSource bSource = new BindingSource();
            bSource.DataSource = _ds.Tables["client"];
            dataGridView2.DataSource = bSource;
            _da.UpdateCommand = cBuilder.GetUpdateCommand();
        }

private void button1_Click(object sender, EventArgs e)
        {

            _dt = _ds.Tables["client"];
            this.dataGridView2.BindingContext[_dt].EndCurrentEdit();
            this._da.Update(_dt);

        }
  • 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-27T07:32:55+00:00Added an answer on May 27, 2026 at 7:32 am

    I assume you’ve got an instance variable called ds, and you’re expecting the Form3_Load method to populate it? That won’t happen – because in Form3_Load you’ve got this:

    DataSet ds = new DataSet();
    

    That’s declaring a new local variable called ds, so unless you explicitly use this.ds in the method, you’re not going to change the value of the instance variable.

    I’m slightly surprised that you’re not getting a NullReferenceException when you click on the button, but maybe you’ve got some code to create an empty DataSet and assign a reference to the ds instance variable somewhere. Anyway, changing the line shown above to just:

    ds = new DataSet();
    

    should fix this problem.

    (I would strongly advise against making database requests in the UI thread, mind you, and you should have a using statement for your connection, but those are separate matters.)

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

Sidebar

Related Questions

Hello can anybody solve this please I'm creating the object in the action class
Hello I have a Problem with some Buttons I would like to create a
Hello everyone i need to convert this code to a function with 2 parameters
Hello I am trying to do a SOAP request here is my code: #
Hello guys i have a problem streaming PDF files with php, i'm using this
hello i'm using this .htaccess code to redirect urls. RewriteEngine on RewriteRule ^printer/([^/\.]+)/?$ printer.php?id=$1
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello StackOverflow community, The air.swf file referenced here: http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_3.html used to launch AIR applications
Hello i am having some problems generating random numbers with C# Now i have
Hello guys I am having some problems with exact matches while doing a NamedQuery.

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.