Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
form1 :-
C#
private void button1_Click(object sender, EventArgs e)
        {
            RPT.FRM_RPT_Car_Details_Date_end frm = new RPT.FRM_RPT_Car_Details_Date_end(dtp_date_End.Value);
            frm.Show();
        }

------------------------------------------------------------------------------
form2 :-

C#
public partial class FRM_RPT_Car_Details_Date_end : Form
   {
       int x;

       SqlConnection con = new SqlConnection("Server= .; Database= WhiteWhaleDB; Integrated Security = true");
       SqlCommand sd;
       SqlDataReader sda;
       string s;

       public FRM_RPT_Car_Details_Date_end(DateTime x)
       {
           InitializeComponent();

           this.x = int.Parse(x);
       }

       private void FRM_RPT_Car_Details_Date_end_Load(object sender, EventArgs e)
       {
           s = "select cars.Car_id,Job_card,convert(varchar,s1.Change_date,101) as Change_date ,convert(varchar,Reload_License.Car_E_date_Licen,101) as Car_E_date_Licen, Service_Type.Servce_desc, Current_dist,Prev_distance as Prev_dist,value_Tashhem as Value from Tashhem inner join cars on Tashhem.Car_id= Cars.Car_id inner join Service_Type on Tashhem.Servce_id = Service_Type.Servce_id inner join Reload_License on Cars.Car_id = Reload_License.Car_id where Reload_License.Car_E_date_Licen = " + x;
           DataSet_Car_Details_end_date ds = new DataSet_Car_Details_end_date();
           SqlDataAdapter dataAdapter = new SqlDataAdapter(s, con);
           dataAdapter.Fill(ds.Tables["Car_End_date"]);
           CrystalReport_Car_Details_date_end report = new CrystalReport_Car_Details_date_end();
           report.SetDataSource(ds.Tables["Car_End_date"]);
           crystalReportViewer_Car_Details_Date_end.ReportSource = report;
           crystalReportViewer_Car_Details_Date_end.Refresh();
       }
   }
Posted

1 solution

Um...A DateTimePicker.Value property is a DateTime - so parsing it as an int is going to fail:
C#
public FRM_RPT_Car_Details_Date_end(DateTime x)
{
    InitializeComponent();
    this.x = int.Parse(x);
}
The attempt will throw an exception, if it compiled...which it wouldn't as there is no overload which accepts a DateTime parameter.
Instead, store it as a DateTime:
C#
DateTime x;
...
public FRM_RPT_Car_Details_Date_end(DateTime x)
{
    InitializeComponent();
    this.x = x;
}

And use a parameterized query to pass it to SQL:
C#
s = "select cars.Car_id,Job_card,convert(varchar,s1.Change_date,101) as Change_date ,convert(varchar,Reload_License.Car_E_date_Licen,101) as Car_E_date_Licen, Service_Type.Servce_desc, Current_dist,Prev_distance as Prev_dist,value_Tashhem as Value from Tashhem inner join cars on Tashhem.Car_id= Cars.Car_id inner join Service_Type on Tashhem.Servce_id = Service_Type.Servce_id inner join Reload_License on Cars.Car_id = Reload_License.Car_id where Reload_License.Car_E_date_Licen = @Date";
 DataSet_Car_Details_end_date ds = new DataSet_Car_Details_end_date();
 SqlDataAdapter dataAdapter = new SqlDataAdapter(s, con);
 dataAdapter.SelectCommand.Parameters.AddWithValue("@Date", x);
 
Share this answer
 
v2

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