title: Inserting data query error
body: <p>i have tried to insert the data by login to the system. my query doesn't have any error, but the exception has thrown by the run time as "Object reference not set to an instance of an object ". check my code and please correct me.</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
      {
          try
          {
              if (TextBox6.Text == " ")
              {
                  string alertmessage = "";
                  alertmessage = "Username should not be blank";
                  this.CreateMessageAlert(this, alertmessage, "alertKey");
                  TextBox6.Focus();
              }
              else if (TextBox7.Text == " ")
              {
                  string alertmessage = "";
                  alertmessage = "Username should not be blank";
                  this.CreateMessageAlert(this, alertmessage, "alertKey");
                  TextBox7.Focus();
              }
              else
              {
                  string sq = "SELECT COUNT(*) FROM tbl_KKSUser WHERE Uname=@un and Password=@pas";
                  SqlCommand sd = new SqlCommand(sq, con);
                  SqlParameter unameparam;
                  unameparam = new SqlParameter("@un", SqlDbType.VarChar, 25);
                  unameparam.Value = TextBox6.Text;
                  sd.Parameters.Add(unameparam);
  
                  string original = TextBox7.Text.Trim();
                  string withhash = original;
                  b1 = Encoding.BigEndianUnicode.GetBytes(withhash);
                  encrypted = Convert.ToBase64String(b1);
                  SqlParameter passparam;
                  passparam = new SqlParameter("@pas", SqlDbType.VarChar, 8000);
                  passparam.Value = Convert.ToString(encrypted);
                  sd.Parameters.Add(passparam);
  
                  con.Open();
                  {
                      int iresults;
                      iresults = Convert.ToInt32(sd.ExecuteScalar().ToString());
                      if (iresults &gt; 0)
                      {
                          string q = "insert into tbl_KKSMaterialRaise(MaterialCode,Source,Category,Population,StockInStores,Specification,PrearedBy,CheckedBy,ApprovedBy,CreatedDate) values(@mc,@sc,@cat,@pop,@sis,@spec,@pb,@cb,@ab,@cd)";
                          SqlCommand dm = new SqlCommand(q, con);
                          dm.Parameters.AddWithValue("@mc", Mcodeddl.SelectedItem.Text);
                          dm.Parameters.AddWithValue("@sc", TextBox1.Text.Trim());
                          dm.Parameters.AddWithValue("@cat", TextBox2.Text.Trim());
                          dm.Parameters.AddWithValue("@pop", TextBox3.Text.Trim());
                          dm.Parameters.AddWithValue("@sis", TextBox4.Text.Trim());
                          dm.Parameters.AddWithValue("@spec", TextBox5.Text.Trim());
                          dm.Parameters.AddWithValue("@pb", PBddl.SelectedItem.Text);
                          dm.Parameters.AddWithValue("@cb", CBddl.SelectedItem.Text);//In this line i have got error
                          dm.Parameters.AddWithValue("@ab", ABddl.SelectedItem.Text);
                          dm.Parameters.AddWithValue("@cd", DateTime.Today);
                          dm.ExecuteNonQuery();
                          string alertmessage = "";
                          alertmessage = "Component Details Saved";
                          this.CreateMessageAlert(this, alertmessage, "alertKey");
                      }
                      else
                      {
                          Response.Write("&lt;script&gt;alert('Invalid Username/Password')&lt;/script&gt;");
                      }
                  }
                  con.Close();
  
              }
          }
          catch (Exception ex)
          {
              Response.Write(ex.Message);
          }
      }
  </code></pre>