Solution For Date Format In Parameterizes Sql Query In 'DD/MM/YYYY' Format
<p>I have asked this question in many sites and my question remain unanswered. Some people advise me to use datetimepicker against maskedtextbox.</p>

<p>It is true that datetimepicker solved the all kind date related problem, whereas masked textbox return a string and that's why it's create a datetime conversion problem in parameterized sql query in C#.</p>

<p>In most case we are not utilise datetimepicker due to time consuming issue. I mean if there is thousand of data entry pending and if we use datetimepicker then over finger are divided between mouse and keyboard. Hence in my case I always use maskedtextbox and it creates a problem of date conversion. I have tried to solve it in the following way:</p>

<pre><code>String sql="insertintodummy(name,date)values(@name,convert(datetime,'"+maskedTextBox1.text+"', 103)"; //  for 'dd/mm/yyyy' format.
sqlcommand cmd=new sqlcommand(sql,con);
cmd.parameters.Add("@name",SqldbType.Varchar).Value= textbox1.text;
cmd.ExecuteNonQuery();
</code></pre>

<p>I think there is no way to utilise the above datetime conversion in a parameterized query with C#, VS-2005.</p>

<p>The above code is useful in case of only datefield must enter way. If there is better way than please suggest. </p>

<p>Now it is perfect Solution here below.</p>

<pre><code>string sql="insert into dummy(name,date)values(@name,@date)";

IFormateprovider Culture = new CultureInfo("fr-FR",True);

DateTime mydate=DateTime.parse(
maskedtextbox1.text,Culture,DateTimeStyles.NocurrentDateDefault
);

sqlcommand cmd=new sqlcommand(sql,con);

cmd.Parameters.Add(@name,SqlDbtypes.Varchar).Values= Textbox1.text;

cmd.Parameters.Add(@date, SqlDbtypes.Datetime).Values=mydate;

cmd.ExecuteNonQuery();
</code></pre>

<p>Thanks.</p>
