Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
select Sheetno,VehicleNo,EDate,SKM,EKM,TKM,Driver1,Driver2,Cleaner,AdvAmt,Mile,Tfrieght,Trecv,TBal,TEAmt,NetBal from TripSheet where VehicleNo ='" & cb_VehNo.Text & "' and EDate between '" & dtp_Fdate.Value & "' and '" & dtp_Ldate.Value & "'



Plz... Say is this correct or not?....
Posted

That's wrong

Yes, have you heard about SQL injection[^]? Never concatenate strings to for SQL things. Use parametrized queries.
C#
SqlCommand cmd = new SqlCommand("SELECT Sheetno,VehicleNo,EDate,SKM,EKM,TKM,Driver1,Driver2,Cleaner,AdvAmt,Mile,Tfrieght,Trecv,TBal,TEAmt,NetBal FROM TripSheet WHERE VehicleNo =@VehicleNo AND EDate BETWEEN @FromDate AND @ToDate",con);
cmd.Parameters.AddWithValue("@VehicleNo", cb_VehNo.Text);
cmd.Parameters.AddWithValue("@FromDate", dtp_Fdate.Value);
cmd.Parameters.AddWithValue("@ToDate", dtp_Ldate.Value);
Interesting read - Give me parameterized SQL, or give me death[^]
 
Share this answer
 
Comments
Maciej Los 6-Jun-12 17:41pm    
Good answer, my 5!
This is correct.


Hope this helps , If yes then plz accept and vote the answer. Any queries / questions on this are always welcome.

Thanks & Regards
RDBurmon.Sr.Software Engineer
 
Share this answer
 
Comments
PunithaSabareeswari 6-Jun-12 6:23am    
i wrote this comment in DateTimePicker2_ValueChanged event.. is it possible..
This appears to be correct.

One point to see is the format of dtp_Fdate.Value and dtp_Ldate.Value, which can be like 'yyyyMMdd' or 'yyyy-MM-dd'.

Further as explained http://msdn.microsoft.com/en-us/library/ms187922.aspx[^] the query includes the records with From and To dates of the Between clause.
 
Share this answer
 
Hi ..

Please try this ,,,

C#
select Sheetno,VehicleNo,EDate,SKM,EKM,TKM,Driver1,Driver2,Cleaner,AdvAmt,Mile,Tfrieght,Trecv,TBal,TEAmt,NetBal from TripSheet where VehicleNo ='" + cb_VehNo.Text + "' and EDate between '" + dtp_Fdate.Value + "' and '" + dtp_Ldate.Value +"'
 
Share this answer
 
Comments
PunithaSabareeswari 6-Jun-12 6:51am    
Sorry... I won't Work..... query selected only that veh.no records it won't check the date
Arul R Ece 6-Jun-12 6:55am    
U which data type used for dates
PunithaSabareeswari 6-Jun-12 7:40am    
datetime data type....

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