hi can you any one help me to correct error

i using c# write private function no error get but not get correct result when debugging

this is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
    public partial class Form4 : Form
    {
        System.Data.OleDb.OleDbConnection con;
        DataSet ds1;
        System.Data.OleDb.OleDbDataAdapter da, d1, d2, d3;

        String a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8;
        int MaxRows = 0;
        int inc = 0;
        public Form4()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            if (inc != 0)
            {
                inc = 0;
                NavigateRecords();
            }
        }

        private void Button9_Click(object sender, EventArgs e)
        {
            if (inc != MaxRows - 1)
            {
                inc++;
                NavigateRecords();
            }
            else
            {
                MessageBox.Show("لا يوجد المزيد من السجلات");
            }
        }

        private void Button10_Click(object sender, EventArgs e)
        {
            if (inc > 0)
            {
                inc--;
                NavigateRecords();
            }
            else
            {
                MessageBox.Show("السجل الأول");
            }
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            if (inc != MaxRows - 1)
            {
                inc = MaxRows - 1;
                NavigateRecords();
            }
        }
 
        private void Button11_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            this.Close();
            f1.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            con = new System.Data.OleDb.OleDbConnection();
            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/data.mdb";
            ds1 = new DataSet();
            con.Open();
            String sql = "SELECT * From programs";
            String s = "SELECT * From student ";
            String s1 = "SELECT * From student_info ";
            String s2 = "SELECT * From student_program ";
            da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
            d1 = new System.Data.OleDb.OleDbDataAdapter(s, con);
            d2 = new System.Data.OleDb.OleDbDataAdapter(s1, con);
            d3 = new System.Data.OleDb.OleDbDataAdapter(s2, con);
            d3.Fill(ds1, "supervisor");
            d2.Fill(ds1, "student_olympic");
            d1.Fill(ds1, "olympic_school");
            da.Fill(ds1, "olympiccomp");
            NavigateRecords();
            MaxRows = ds1.Tables["student"].Rows.Count;
        }
        private void NavigateRecords()
        {
            //DataRow dRow = ds1.Tables["student"].Rows[inc];
            DataRow dRow = ds1.Tables["student"].Rows[inc]; 
            textBox9.Text = ds1.Tables["programs"].Rows[inc].ItemArray.GetValue(0).ToString();
            textBox17.Text = ds1.Tables["programs"].Rows[inc].ItemArray.GetValue(1).ToString();
            ComboBox2.Text = ds1.Tables["programs"].Rows[inc].ItemArray.GetValue(2).ToString();
            TextBox7.Text = ds1.Tables["student_info"].Rows[inc].ItemArray.GetValue(1).ToString();
            textBox1.Text = ds1.Tables["student_info"].Rows[inc].ItemArray.GetValue(2).ToString();
            ComboBox5.Text = ds1.Tables["student_info"].Rows[inc].ItemArray.GetValue(3).ToString();
            TextBox12.Text = ds1.Tables["student_info"].Rows[inc].ItemArray.GetValue(4).ToString();
            TextBox14.Text = ds1.Tables["student_info"].Rows[inc].ItemArray.GetValue(5).ToString();
            //from student table
            TextBox6.Text = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(0).ToString();
            a1 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(1).ToString();
            if (a1 == RadioButton9.Text)
                RadioButton9.Checked = true;
            else if (a1 == RadioButton10.Text)
                RadioButton10.Checked = true;
            TextBox24.Text = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(2).ToString();
            TextBox8.Text = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(3).ToString();
            TextBox25.Text = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(4).ToString();
            TextBox13.Text = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(5).ToString();
            TextBox11.Text = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(6).ToString();
            a2 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(7).ToString();
            if (a2 == "نعم")
                CheckBox11.Checked = true;
            else if (a2 == "لا")
                CheckBox11.Checked = false;
            a3 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(8).ToString();
            if (a3 == "نعم")
                CheckBox12.Checked = true;
            else if (a3 == "لا")
                CheckBox12.Checked = false;
            a4 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(9).ToString();
            if (a4 == "نعم")
                CheckBox13.Checked = true;
            else if (a4 == "لا")
                CheckBox13.Checked = false;
            a5 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(10).ToString();
            if (a5 == "نعم")
                CheckBox14.Checked = true;
            else if (a5 == "لا")
                CheckBox14.Checked = false;
            a6 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(11).ToString();
            if (a6 == "نعم")
                CheckBox18.Checked = true;
            else if (a6 == "لا")
                CheckBox18.Checked = false;
            a7 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(12).ToString();
            if (a7 == "نعم")
                CheckBox17.Checked = true;
            else if (a7 == "لا")
                CheckBox17.Checked = false;
            a8 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(13).ToString();
            if (a8 == "نعم")
                CheckBox15.Checked = true;
            else if (a8 == "لا")
                CheckBox15.Checked = false;
            b1 = ds1.Tables["student"].Rows[inc].ItemArray.GetValue(14).ToString();
            if (b1 == "نعم")
                CheckBox16.Checked = true;
            else if (b1 == "لا")
                CheckBox16.Checked = false;
          
    }
}

this message appear


[img]http://www2.0zz0.com/2011/08/14/03/790131206.png[/img]

Where does it fail?
What result are you expecting?

I am expecting get infromation from data to form in text box and check box

Can you translate the message into English? Does it say something about connection already in use?

message is object reference not set to an instance of an object

And what line does it say this occurs in? Or do I just get to guess?

Also when you close the form in line 74 execution stops, so line 75 will not run.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.