1

I am using SQL to retrive data from SQL-Server in C#, like below:

var cmd = new SqlCommand(
    "select *, replace(trucknocn, char(10), '') trucknocn1 from deliverylist  where deliverydate=@scantime", sqlCon);             
cmd.Parameters.Add("@scantime", SqlDbType.VarChar, 10).Value
    = Calendar1.SelectedDate.ToString("yyyy-MM-dd");            

da.SelectCommand = cmd;

My problem is that am I correct in doing this to avoid regional setting problems for my client application machine. Anything that I can do to totally avoid the regional setting problem?

Thanks

1
  • When you say regional setting problem, are you talking about different time zones? Commented Apr 12, 2013 at 10:19

2 Answers 2

5

Is deliverydate a varchar? I don't think so.
You can just add the parameter as DateTime:

cmd.Parameters.Add("@scantime", SqlDbType.DateTime).Value = Calendar1.SelectedDate;

Then all the regional setting problem are gone, since there is no string->Date->string conversion, and the comparaison are made base on the real date value, not just a string representation.

Sign up to request clarification or add additional context in comments.

Comments

0

If deliverydate is varchar type then I did not find any problem in your code,

But if deliverydate is datetime then change the code like following -

your's

cmd.Parameters.Add("@scantime", SqlDbType.VarChar, 10).Value = Calendar1.SelectedDate.ToString("yyyy-MM-dd");

New Code:

cmd.Parameters.Add("@scantime", SqlDbType.DateTime).Value = Calendar1.SelectedDate;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.