Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1022227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:26:02+00:00 2026-05-16T11:26:02+00:00

am using C#, VS 2005 and SQL 2000 I have date conversion problem my

  • 0

am using C#, VS 2005 and SQL 2000

I have date conversion problem my SQL table having field as below

Fields:

datefrom    
dateto

My SQL query in C# is

string sql = "insert into companymast (cname, datefrom, dateto) values(@cname, @datefrom, @dateto)";

SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add("@cname",SqlDbType.Varchar(50)).Values = cname.text;
cmd.Parameters.Add("@datefrom",SqlDbType.Datetime).Values = maskedTextBox1.text;
cmd.Parameters.Add("@dateto",SqlDbType.Datetime).Values = maskedTextBox2.text;
cmd.ExecuteNonQuery();

But the above throw Error Like date non conversion string to date

I have to put date in dd/MM/yyyy format code, 103

so how do i do?

Help me out, please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:26:02+00:00Added an answer on May 16, 2026 at 11:26 am

    maskedBox1.text is a string. You’re assigning that to a SqlParameter‘s data member, and it tries to convert whatever it receives to the data type you request.

    A more solid solution would be to convert to DateTime explicitly, and pass the converted value to the SqlParameter. This way, you have more control over the conversion, and you’ll see exactly where and why it goes wrong when it does. Example:

    DateTime fromDate = DateTime.Parse(maskedTextBox1.text);
    cmd.Parameters.Add("@datefrom",SqlDbType.Datetime).Values= fromDate;
    

    For DateTime.Parse, see: http://msdn.microsoft.com/en-us/library/1k1skd40.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[using SQL Server 2005] I have a table full of users, I want to
I’m using SQL Server 2005 and I have a table contains a column of
I'm using MS SQL 2005 and I have created a CTE query to return
The excel spreadsheet is connecting to SQL server 2005 using the connection string below:
I'm having a C++ application connecting to the MS SQL Server 2005 using CDynamicAccessor.
Using SQL Server 2005 I have a query that gets child records from bundles
Im using SQL Server 2005. I have a table1 with 3 columns. And table2
I have been using LINQPad to prototype some queries against a SQL 2000 database,
We have an installation of MOSS 2007 that is using MS SQL 2000 as
In SQL Server 2005, I have a table say tbl_Info. There I have one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.