none
binding the 2 textboxes for date value to be displayed on the reportviewer RRS feed

  • Question

  • hello there,

                  please,help me ,i have 2 textboxes which takes date only the user should select and a combo box for selecting a employee name.

    the report viewer i have should display the date from the first and the second textbox(for example)textbox1 :'1/05/2010 and textbox2 :'02/06/2010' these values are not fixed and the user would put the value he like but between two months for displaying employee number of worked hours.

    this is the code for populating combobox for displaying employee names
     private void populateComboBox()
        {
          SqlConnection c = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=fingertec;Data Source=npalx39");
    
          SqlDataReader rdr = null;
          SqlDataReader drReport;
          try
          {
            c.Open();
            //comboBox1.Items.Clear();
    
            string sql = "SELECT name1 from employee where storeid=12";
    
    
            SqlCommand cmd = new SqlCommand(sql, c);
            // cmd.Parameters.AddWithValue("@name1", comboBox1.Text);
            // DataSet finger = new DataSet();
            // NorthwindDataSet northwindDataSet = new NorthwindDataSet();
            DataSet dsReport = new fingertecDataSet();
            ReportDataSource rds = new ReportDataSource();
            rds.Name = "fingertecDataSet_attendnace2";
            rds.Value = dsReport.Tables[0];
            reportViewer1.LocalReport.DataSources.Add(rds);
            //load report viewer
            reportViewer1.RefreshReport();
            this.reportViewer1.RefreshReport();
    
            //customersTableAdapter.Fill(northwindDataSet.Customers);
            //////////
            //NorthwindDataSet northwindDataSet = new NorthwindDataSet();
            // fingertecDataSetTableAdapters.employeeTableAdapter employeeTableAdapter =
            //  new fingertecDataSetTableAdapters.employeeTableAdapter();
            fingertecDataSetTableAdapters.attendance2TableAdapter attendance2TableAdapter =
             new fingertecDataSetTableAdapters.attendance2TableAdapter();
            //this
            // attendance2TableAdapter.Fill("fingertecDataSet_attendance2",comboBox1.SelectedItem.ToString());
    
            //  customersTableAdapter.Fill(northwindDataSet.Customers);
    
    
            ///////////////////
    
            StringWriter res = new StringWriter();
            rdr = cmd.ExecuteReader();
            if (rdr != null)
            {
              while (rdr.Read())
              {
    
                comboBox1.Items.Add(rdr["name1"]);
                // listBox1.Items.Add(string.Format("{0}:{1}",rdr[0],rdr[1]));            //cboPaintSysReport.Items.Add(dr["paintsys_code"]);
              }
              MessageBox.Show(res.ToString());
            }
    
    
    
          }
          catch (Exception ex)
          {
            MessageBox.Show(ex.ToString());
          }
          finally
          {
            if (rdr != null)
            {
              rdr.Close();
            }
            c.Close();
          }
        }
    and selectedindex changed which display different employees
    
     private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
               this.attendance2TableAdapter.FillBy(fingertecDataSet.attendance2, comboBox1.SelectedItem.ToString());
          this.reportViewer1.RefreshReport();
        }
    this one one which displays the data which should be rendered on the report for showing employee no,name,check in,datetime in,check out,datetime out and hours and minutes.the values for datetime1 and datetime2 will be on textbox1 and textbox2
    
     SqlConnection c = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=fingertec;Data Source=npalx39");
    
       SqlDataReader rdr = null;
       DateTime datetime1;
       DateTime datetime2;
       
      
         // SqlDataReader drReport;
          try
          {
            c.Open();
            //comboBox1.Items.Clear();
          //  string sql = "SELECT enrollno,datetime1,datetime2 from attendance2 where datetime1>='" + textBox1.Text + "'" +"and datetime2<='" + textBox2.Text +"'" ;
           // string sql = "SELECT datetime1,enrollno from attendance2 where datetime1>='" + dateTimePicker1.Value + "'";
    
            string sql = "select distinct a1.enrollno,e.name1,a2.datetime1 ,a2.check1 ,a1.datetime1 ,a1.check2 ," +
      "datediff(second,a2.datetime1,a1.datetime1)/3600 as 'Hours' , datediff(second,a2.datetime1,a1.datetime1)%3600/60 as 'Minutes'" +
      "from attendance2 as a1 inner join " +
      "employee as e on a1.EnrollNo=e.EnrollNo inner join attendance2 as a2 on a2.EnrollNo=e.EnrollNo inner join store st on a2.StoreID=st.StoreID where a2.StoreID=12 and a1.enrollno=a2.EnrollNo and " +
      "a1.datetime1>='" + textBox1.Text + "'" + " and a1.datetime2 <='" + textBox2.Text + "'" + "and a2.Check1 = 'Check In' AND a1.check2 = 'Check Out'" +
      "AND a1.datetime1 = (SELECT distinct Min(datetime1) FROM attendance2 WHERE a1.EnrollNo = a2.EnrollNo AND datetime1 >a2.datetime1)";
     
       SqlCommand cmd = new SqlCommand(sql, c);

    i tried to populate the textbox here but it doesn't displasy the required value in the reportviewer and i don't know which event i should use in the textbox to make it fires like the combobox

    private void populateTextBox()
        {
          SqlConnection c = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=fingertec;Data Source=npalx39");
    
          SqlDataReader rdr = null;
          SqlDataReader drReport;
          try
          {
            c.Open();
            //comboBox1.Items.Clear();
    
            string sql = "SELECT datetime1,datetime2 from attendance2 where datetime1>='" + textBox1.Text + "'" + " and datetime2 <='" + textBox2.Text + "'";
    
    
            SqlCommand cmd = new SqlCommand(sql, c);
            // cmd.Parameters.AddWithValue("@name1", comboBox1.Text);
            // DataSet finger = new DataSet();
            // NorthwindDataSet northwindDataSet = new NorthwindDataSet();
            DateTime datetime1;
            DateTime datetime2;
    
    
            DataSet dsReport = new fingertecDataSet();
            ReportDataSource rds = new ReportDataSource();
            rds.Name = "fingertecDataSet_attendance2";
            rds.Value = dsReport.Tables[0];
            reportViewer1.LocalReport.DataSources.Add(rds);
            //load report viewer
            reportViewer1.RefreshReport();
            this.reportViewer1.RefreshReport();
    
            //customersTableAdapter.Fill(northwindDataSet.Customers);
            //////////
            //NorthwindDataSet northwindDataSet = new NorthwindDataSet();
           // fingertecDataSetTableAdapters.employeeTableAdapter employeeTableAdapter =
            //  new fingertecDataSetTableAdapters.employeeTableAdapter();
            fingertecDataSetTableAdapters.attendance2TableAdapter attendance2TableAdapter =
             new fingertecDataSetTableAdapters.attendance2TableAdapter();
            //this
            // attendance2TableAdapter.Fill("fingertecDataSet_attendance2",comboBox1.SelectedItem.ToString());
    
            //  customersTableAdapter.Fill(northwindDataSet.Customers);
    
    
            ///////////////////
            datetime1 = Convert.ToDateTime(cmd.ExecuteScalar());
            datetime2 = Convert.ToDateTime(cmd.ExecuteScalar());
    
           //  StringWriter res = new StringWriter();
           //  rdr = cmd.ExecuteReader();
            // if (rdr != null)
           // {
             // while (rdr.Read())
             // {
    
                textBox1.DataBindings.Add("Text", rds, "attendance2.datetime1");
                textBox2.DataBindings.Add("Text", rds, "attendance2.datetime2");            // comboBox1.Items.Add(rdr["name1"]);
                // listBox1.Items.Add(string.Format("{0}:{1}",rdr[0],rdr[1]));            //cboPaintSysReport.Items.Add(dr["paintsys_code"]);
             //  }
              // MessageBox.Show(res.ToString());
            }
    
    
    
         
          catch (Exception ex)
          {
            MessageBox.Show(ex.ToString());
          }
          finally
          {
            // if (rdr != null)
            // {
            //  rdr.Close();
           // }
            c.Close();
          }
        }

    please ,tell me what's the problem here,

    thanks in advance,

    Sunday, June 27, 2010 11:28 AM

All replies

  • plz anyone can answer me,i have this error and i dont underastand it

    Cannot bind to the property or column datetime1 on the DataSource.
    Parameter name: dataMember

    Tuesday, June 29, 2010 6:43 AM