Click here to Skip to main content
15,916,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
kindly help me....i don't know what's the problem with code i am not getting data in report between two dates selected from two datetimepicker....plz help me

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace cargo
{
    public partial class Employee_Information : Form
    {
        SQLConnection db = new SQLConnection();
        public Employee_Information()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string str1 = "select * from employeeinfo where Date between '" + dateTimePicker1.Text + "' and '"+dateTimePicker2.Text+"' ";
                db.cmd.Connection = db.conn;
                db.cmd.CommandText = str1;
                SqlDataAdapter da = new SqlDataAdapter(str1,db.conn);
                da.Fill(db.ds, "employeeinfo ");
                CrystalReport1 cr = new CrystalReport1();
                cr.SetDataSource(db.ds.Tables[0]);
                crystalReportViewer1.ReportSource = cr;
                crystalReportViewer1.RefreshReport();
            }
            catch (Exception ex)
            {
                MessageBox.Show("error in query" + ex.Message);
            }
        

        }

        private void Employee_Information_Load(object sender, EventArgs e)
        {
            db.DBConnect();
        }

        private void Employee_Information_FormClosed(object sender, FormClosedEventArgs e)
        {
            db.DBClose();
        }

       
    }
}
Posted

1 solution

Check date format in your DataBase.
If they are different ,then problem occuers.
try to use same format with both datetime picker and Database.
to set DateTimePicker foramt use
:
C#
dateTimePicker1.CustomFormat = "dd-MM-yyyy";
 dateTimePicker1.Format = DateTimePickerFormat.Custom;
 
Share this answer
 
Comments
duaa2 15-Sep-11 2:55am    
date entered in table is through datetimepicker.....so my datbase and datetimepicker date format are same

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