You are subscribed to this thread Object reference not set to an instance of an ob

This is a discussion on You are subscribed to this thread Object reference not set to an instance of an ob within the C# Programming forums, part of the General Programming Boards category; when i build the program there is no error or warning but after running the program and clicked the checkboxlist ...

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71

    Object reference not set to an instance of an object error

    when i build the program there is no error or warning but after running the program and clicked the checkboxlist i got this error.

    i wanted to take the person's id to take his informations.

    Code:
    //i take the group from dropdownlist
    protected void ddlGrup_SelectedIndexChanged(object sender, EventArgs e)
        {
            cblNames.Items.Clear();
    
            String grup = ddlGrup.SelectedItem.ToString();
    
            switch (grup)
            {
                case "Aile":
                    OleDbConnection con = dbConnection.GetConnectionObject();
                    OleDbCommand cmd = new OleDbCommand("select kisi_id,kisi_ad,kisi_soyad from kisi where k_id=@kid and grup=@gname", con);
                    cmd.Parameters.AddWithValue("@kid", Session["k_id"].ToString());
                    cmd.Parameters.AddWithValue("@gname", "Aile");
                    con.Open();
                    //OleDbDataReader rdr = cmd.ExecuteReader();
                    //while(rdr.HasRows)
                    //{
                    //    i = (String)(rdr.GetValue(0) + " " + rdr.GetValue(1));
                    //    kisi_ad = (String)(rdr.GetValue(0));
                    //}
                    OleDbDataAdapter adapterr = new OleDbDataAdapter(cmd);
                    DataTable dat = new DataTable();
                    adapterr.Fill(dat);
                    int rCount;
    
                    for (rCount = 0; rCount <= dat.Rows.Count - 1; rCount++)
                    {
                        //lbName.Items.Add(dat.Rows[rCount]["kisi_ad"] + " " + dat.Rows[rCount]["kisi_soyad"]);
                        //lbName.Visible = true;
    
                        cblNames.Items.Add(dat.Rows[rCount]["kisi_ad"] + " " + dat.Rows[rCount]["kisi_soyad"]);
     cblNames.Items[cblNames.Items.Count - 1].Attributes.Add("ID", dt.Rows[RCount]["kisi_id"].ToString());
                        //kisi_ad = dat.Rows[rCount]["kisi_ad"].ToString();
                    }
                    con.Close();
                    break;
         
                case "Arkadaş":
                    OleDbConnection conn = dbConnection.GetConnectionObject();
                    //OleDbCommand c = new OleDbCommand("SELECT kisi_ad FROM kisi WHERE k_id=@kidd",conn);
                    //c.Parameters.AddWithValue("@kidd", Session["k_id"].ToString());
                    OleDbCommand cmdd = new OleDbCommand("select kisi_id,kisi_id,kisi_ad,kisi_soyad from kisi where k_id=@kid and grup=@gname", conn);
                    cmdd.Parameters.AddWithValue("@kid", Session["k_id"].ToString());
                    cmdd.Parameters.AddWithValue("@gname", "Arkadaş");
                    conn.Open();
                    OleDbDataAdapter adapter = new OleDbDataAdapter(cmdd);
                    DataTable dt = new DataTable();
                    adapter.Fill(dt);
                    int RCount;
    
                    for (RCount = 0; RCount <= dt.Rows.Count - 1; RCount++)
                    {
                        cblNames.Items.Add(dt.Rows[RCount]["kisi_ad"] + " " + dt.Rows[RCount]["kisi_soyad"]);
                        cblNames.Items[cblNames.Items.Count - 1].Attributes.Add("ID", dt.Rows[RCount]["kisi_id"].ToString());
                    }
                    conn.Close();
                    break;
                    
                case "İş Arkadaşı":
                    OleDbConnection connn = dbConnection.GetConnectionObject();
                    OleDbCommand cmddd = new OleDbCommand("select kisi_id,kisi_ad,kisi_soyad from kisi where k_id=@kid and grup=@gname", connn);
                    cmddd.Parameters.AddWithValue("@kid", Session["k_id"].ToString());
                    cmddd.Parameters.AddWithValue("@gname", "İş Arkadaşı");
                    connn.Open();
                    //OleDbDataReader rdrrr = cmddd.ExecuteReader();
                    //while (rdrrr.HasRows)
                    //{
                    //    //i = (String)(rdrrr.GetValue(0) + " " + rdrrr.GetValue(1));
                    //    kisi_ad = (String)(rdrrr.GetValue(0));
                    //}
                    OleDbDataAdapter adapterrr = new OleDbDataAdapter(cmddd);
                    DataTable dta = new DataTable();
                    adapterrr.Fill(dta);
                    int rcount;
    
                    for (rcount = 0; rcount <= dta.Rows.Count - 1; rcount++)
                    {
                        //lbName.Items.Add(dta.Rows[rcount]["kisi_ad"] + " " + dta.Rows[rcount]["kisi_soyad"]);
                        //lbName.Visible = true;
    
                        cblNames.Items.Add(dta.Rows[rcount]["kisi_ad"] + " " + dta.Rows[rcount]["kisi_soyad"]);
     cblNames.Items[cblNames.Items.Count - 1].Attributes.Add("ID", dt.Rows[RCount]["kisi_id"].ToString());
                        //kisi_ad = dta.Rows[rcount]["kisi_ad"].ToString();
                        //Response.Write(kisi_ad);
                    }
                    connn.Close();
                    break;
            }    
        }
    
    //here i choose one element from checkboxlist an the informations are listed to the labels
     protected void cblNames_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblAd.Text = "";
            lblSoyad.Text = "";
            lblMeslek.Text = "";
            lblEvtel.Text = "";
            lblIstel.Text = "";
            lblCep1.Text = "";
            lblCep2.Text = "";
            lblEvAdres1.Text = "";
            lblEvAdres2.Text = "";
            lblSehir.Text = "";
            lblIsAdres1.Text = "";
            lblIsAdres2.Text = "";
            lblEmail.Text = "";
       
            string kisi_name = cblNames.SelectedItem.ToString();
            char[] toSplit ={ ' ' };
            string[] words = kisi_name.Split(toSplit);
    
            cblNames.SelectedItem.Selected = false;
    
            OleDbConnection connect = dbConnection.GetConnectionObject();
            OleDbCommand command = new OleDbCommand("SELECT * FROM kisi WHERE kisi_id=@pid", connect);
            command.Parameters.AddWithValue("@pid", cblNames.Attributes["ID"].ToString() );--->>ERROR
            connect.Open();
    
            OleDbDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                lblAd.Text = reader["kisi_ad"].ToString();
                lblSoyad.Text = reader["kisi_soyad"].ToString();
                lblMeslek.Text = reader["kisi_meslek"].ToString();
                lblEvtel.Text = reader["kisi_evtel"].ToString();
                lblIstel.Text = reader["kisi_istel"].ToString();
                lblCep1.Text = reader["kisi_cep1"].ToString();
                lblCep2.Text = reader["kisi_cep2"].ToString();
                lblEvAdres1.Text = reader["kisi_evadres"].ToString();
                lblEvAdres2.Text = reader["kisi_evadres2"].ToString();
                lblSehir.Text = reader["kisi_sehir"].ToString();
                lblIsAdres1.Text = reader["kisi_isadres"].ToString();
                lblIsAdres2.Text = reader["kisi_isadres2"].ToString();
                lblEmail.Text = reader["kisi_email"].ToString();
            }
            connect.Close();
    }
    what can i do? i m waiting your answers.Thanks...
    Last edited by Aga^^; 07-24-2009 at 01:32 AM.

  2. #2
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    i fixed it ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  2. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 10:34 PM
  3. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  4. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21