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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:54:42+00:00 2026-05-23T08:54:42+00:00

I have been following a tutorial on the internet it can be found at

  • 0

I have been following a tutorial on the internet it can be found at Add a New Record to the Database. I have code that is identical for input in to a dataset and database, but I get this error

Object reference not set to an
instance of an object.

here is my full code

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        System.Data.SqlClient.SqlConnection con;
        System.Data.SqlClient.SqlDataAdapter da;
        DataSet ds1;


        int MaxRows = 0;
        int inc = 0;

        private void Form1_Load(object sender, EventArgs e)
        {
            con = new System.Data.SqlClient.SqlConnection();
            ds1 = new DataSet();

            con.ConnectionString = "Data Source=localhost;Initial Catalog=Kart_Setup;Integrated Security=True;Pooling=False";

            con.Open();

            da.Fill(ds1, "Setup");   
        }

        private void clr_Click(object sender, EventArgs e)
        {


        }

        private void save_Click(object sender, EventArgs e)
        {
            System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da);


          DataRow dRow = ds1.Tables["Setup"].NewRow();

          dRow[1] = FL.Value;
          dRow[2] = FR.Value;
          dRow[3] = RL.Value;
          dRow[4] = RR.Value;

          ds1.Tables["Setup"].Rows.Add(dRow);

          MaxRows = MaxRows + 1;
          inc = MaxRows - 1;

          da.Update(ds1, "Setup");

          MessageBox.Show("Setup Added");

          con.Close();
        }
    }
}

Any help would be appreciated thanks in advance

  • 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-23T08:54:43+00:00Added an answer on May 23, 2026 at 8:54 am

    You need to declare ds to something… try….

    EDIT: Fixed code to add datatable to the dataset.

    DataSet ds1 = new DataSet();
    DataTable dt = new DataTable("Setup");
    ds1.Tables.Add(dt);
    DataRow dRow = ds1.Tables["Setup"].NewRow();
    

    Also, be sure to initialize all variables, these look suspicious:

    MaxRows = MaxRows + 1;
    inc = MaxRows - 1;
    

    It looks as though these are declared in the class itself, put this outside of the function:

    public intMaxRows = 0;
    public int inc = 0;
    

    Also, I do not know what da is supposed to be, but you’ll need to instantiate that as well.

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

Sidebar

Related Questions

I'm new to NHibernate... I have been following this NHibernate Tutorial from Gabriel Schenker
I have been following some MVC tutorials that connect to a sql mdf database
I am new to Ajax and have been following a tutorial from JQuery.com. I
I'm new to jQuery and have been following the tutorial here for a Panel
I am new to WP7 programming and I have been following this tutorial http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx
I have been following the ASP.Net Movie Database Tutorial , and it was all
As I have been following a MusicStore tutorial, new MVC3 project created a following
I have been following a tutorial that remotely downloads an image to an imageview,
I'm a newcomer to Rails, and have been following the tutorial on the rails
Hi I am quite new to php but i have been following some tutorials

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.