Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

This is my code. I click combobox value that time the value is not selected.the report it will come Empty only..

  Mycombobox name = cmbsummary


private void cmbsummary_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strQry;
            SqlConnection objConn = new SqlConnection(ConfigurationSettings.AppSettings["TrafficDB"]);
            strQry = "Select FileID ,Sitecode from   TBL_TXN_MAIN  order by Sitecode";
            SqlCommand objCmdVtype = new SqlCommand(strQry, objConn);
            SqlDataAdapter objDAVtype = new SqlDataAdapter(objCmdVtype);
            DataSet dsVtype = new DataSet();
            objDAVtype.Fill(dsVtype, "dtVtype");
            cmbsummary.DataSource = dsVtype.Tables["dtVtype"];
            cmbsummary.DisplayMember = "Sitecode";
            cmbsummary.ValueMember = "FileID";
            dsVtype.Dispose();
        }
          private void cmbtypesummary_click(object sender, EventArgs e)------Filling data in this code
        {
            string strQry;
            SqlConnection objConn = new SqlConnection(ConfigurationSettings.AppSettings["TrafficDB"]);
            strQry = "Select FileID ,Sitecode from   TBL_TXN_MAIN  order by Sitecode";
            SqlCommand objCmdVtype = new SqlCommand(strQry, objConn);
            SqlDataAdapter objDAVtype = new SqlDataAdapter(objCmdVtype);
            DataSet dsVtype = new DataSet();
            objDAVtype.Fill(dsVtype, "dtVtype");
            cmbtypesummary.DataSource = dsVtype.Tables["dtVtype"];
           cmbtypesummary.DisplayMember = "Sitecode";
           cmbtypesummary.ValueMember = "FileID";
            dsVtype.Dispose();
        }
       private void SiteSummary()---------- Sitesummary code
        {
            try
            {
                rpSiteSummary objRpt;
                objRpt = new rpSiteSummary();

                SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["TrafficDB"]);

                String strQry = string.Empty;
                strQry = "Select Sitecode,count(1) Total from TBL_TXN_MAIN where Sitecode =(cmbsummary.text)group by Sitecode"; 
                 // Pls check  this query.  ..                                                                
                  
                SqlDataAdapter adapter = new SqlDataAdapter(strQry, myConnection);

                DataSet Ds = new DataSet();
                adapter.Fill(Ds, "DTSiteSummary");

                //if (Ds.Tables[0].Rows.Count == 0)
                //{
                //    return;
                //}

                objRpt.SetDataSource(Ds);

                frmReports reportsform = new frmReports();
                reportsform.crystalReportViewer.ReportSource = objRpt;
                reportsform.Show();
            }
            catch (Exception ex)
            {
            }
Posted
Updated 11-Feb-13 5:33am
v2
Comments
Sergey Alexandrovich Kryukov 11-Feb-13 11:55am    
To start with, what is "ComboBox". Full type name, please. Or tag your UI library or application type.
—SA
WaZoX 11-Feb-13 13:42pm    
I would guess it's standard Windows.Forms but I agree that it's really unclear.
Sergey Alexandrovich Kryukov 11-Feb-13 18:15pm    
I think we should not answer at all with we have so much of guesswork as with the use of UI library. After all, OP is the most interested in answer, let he/him answer.
—SA

1 solution

As usual I would recommend the API documentation first for problems like this http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.aspx[^]. You can e.g. use the property ComboBox.SelectedIndex to check if any object is selected. I am not certain what your question is about though. Could you try to be more specific and try to avoid source code if it's not really needed since it's normally the worst way of explaining a problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900