private void cbCategory_SelectedIndexChanged(object sender, EventArgs e) { string cat = cbCategory.Text; SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\New.mdf;Integrated Security=True;User Instance=True"; con.Open(); SqlCommand cmd = new SqlCommand("select Category From tblItem where Category='" + cat + "'", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { cat1 = dt.Rows[0][0].ToString(); } con.Close(); if (cat == cat1) { //string cat = cbCategory.Text; SqlConnection conn = new SqlConnection(); conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\New.mdf;Integrated Security=True;User Instance=True"; conn.Open(); SqlCommand cmd1 = new SqlCommand("select sum(quantity) from tblItem where Category='" + cat + "'", conn); SqlDataAdapter daaa = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); daaa.Fill(dt1); if (dt1.Rows.Count > 0) { quantit = Convert.ToInt32(dt1.Rows[0][0].ToString()); } conn.Close(); textBox1.Text = Convert.ToString(quantit); SqlConnection con4 = new SqlConnection(); con4.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\New.mdf;Integrated Security=True;User Instance=True"; con4.Open(); SqlCommand cmd4 = new SqlCommand("select Category From tblSalesEntry where Category='" + cat + "'", con4); SqlDataAdapter da4 = new SqlDataAdapter(cmd4); DataTable dt4 = new DataTable(); da4.Fill(dt4); if (dt4.Rows.Count > 0) { cat1 = dt4.Rows[0][0].ToString(); } con4.Close(); if (cat == cat1) { SqlConnection con1 = new SqlConnection(); con1.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\New.mdf;Integrated Security=True;User Instance=True"; con1.Open(); SqlCommand cmdd = new SqlCommand("select sum(Quantity) from tblSalesEntry where Category='" + cat + "'", con1); SqlDataAdapter daa = new SqlDataAdapter(cmdd); DataTable dtt = new DataTable(); daa.Fill(dtt); if (dtt.Rows.Count > 0) { quanti = Convert.ToInt32(dtt.Rows[0][0].ToString()); } con1.Close(); } /*else { MessageBox.Show("THIS CATEGORY IS NOT SALED"); }*/ int stoc = quantit - quanti; textBox1.Text = Convert.ToString(stoc); } else { MessageBox.Show("CATEGORY DOES NOT EXIST IN TABLE"); this.Close(); } }
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'ComboBox'. at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.ComboBox.CreateHandle() at System.Windows.Forms.Control.get_Handle() at System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, Int32 lparam) at System.Windows.Forms.Control.EndUpdateInternal(Boolean invalidate) at System.Windows.Forms.ComboBox.EndUpdate() at System.Windows.Forms.ComboBox.OnDataSourceChanged(EventArgs e) at System.Windows.Forms.ListControl.SetDataConnection(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean force) at System.Windows.Forms.ListControl.DataSourceDisposed(Object sender, EventArgs e) at System.ComponentModel.Component.Dispose(Boolean disposing) at System.Windows.Forms.BindingSource.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.ComponentModel.Container.Dispose(Boolean disposing) at System.ComponentModel.Container.Dispose() at Bill.StockList.Dispose(Boolean disposing) in C:\Users\Ravu\Desktop\Bill\Bill\StockList.Designer.cs:line 18 at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Form.WmClose(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)