Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make monthly report on button click event and display through crystal report.
tc_np = tab control name
tbprint = tab name where i put crystalreportviewer.
mnt = is crystal report where i define or design according table of patient_info
crv = is crystalreportviewer name.

C#
private void mntbtn_Click(object sender, EventArgs e)
        {
            tc_np.SelectedTab = tbprint;
            try
            {
                cn.Open();
                DataSet ds2 = new DataSet();
                //SELECT * FROM MyTable WHERE DATEDIFF(mm, MyDateColumn, GETDATE()) = 0
                mnt m = new mnt();
                OleDbCommand cmdmnt = new OleDbCommand("select * from patient_info where DATEDIFF(m, E_date, DATE())=0",cn);
                OleDbDataAdapter da = new OleDbDataAdapter(cmdmnt);
                da.Fill(ds2, "patient_info");
                m.SetDataSource(ds2.Tables["patient_info"]);
                crv.ReportSource = m;
                crv.RefreshReport();
                cn.Close();
            }
            catch (Exception p)
            {
                MessageBox.Show(p.Message,"error",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }

        }


error at:
C#
da.Fill(ds2, "patient_info")

error: "no value given for one or more required parameters"


What I have tried:

i tried chages in date(), give condition for as Datediff(mm,E_date,Date())=30, and etc.
Posted
Updated 1-Oct-16 9:07am
Comments
[no name] 1-Oct-16 11:15am    
Based on your lack of information here, my complete and total guess is that "m" being passed to DateDiff is not what you think it is.

1 solution

If your DBMS is SQL Server then try GETDATE() instead of DATE(), because there is no such function. GETDATE() is used to get the current date of the DB server.
C#
OleDbCommand cmdmnt = new OleDbCommand("select * from patient_info where DATEDIFF(m, E_date, GETDATE())=0",cn);


Hope, it helps :)
Please let me know if I am missing something here.
 
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