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 8070811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:30:53+00:00 2026-06-05T13:30:53+00:00

I have written a code for store the current date & time value. It

  • 0

I have written a code for store the current date & time value. It was working the day before yesterday exactly as I wanted. But today it shows error "Arithmetic overflow error converting expression to data type datetime. The statement has been terminated."

Can any body help me? Here is my code,

protected void Button1_Click(object sender, EventArgs e)
{
    con.Open();
    string q;
    q = "insert into tbl_MR(RequirementFor,Category,MRNO,CreatedBy,CreatedDate)values(@rf,@cat,@mr,@cb,@cd)";
    SqlCommand cmd = new SqlCommand(q, con);
    cmd.Parameters.AddWithValue("@rf", CCddl.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@mr", TextBox1.Text.Trim());
    cmd.Parameters.AddWithValue("@cat", TextBox3.Text.Trim());
    cmd.Parameters.AddWithValue("@cb", Session["loginid"].ToString());
    string cd1, date1;
    cd1 = System.DateTime.Today.ToShortDateString();
    date1 = Convert.ToDateTime(cd1).ToString("dd/MM/yyyy");
    cmd.Parameters.AddWithValue("@cd", date1.ToString());
    cmd.ExecuteNonQuery();
    string alertmessage = "";
    alertmessage = "Component Details Saved";
    this.CreateMessageAlert(this, alertmessage, "alertKey");
    con.Close();  
}
  • 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-06-05T13:30:54+00:00Added an answer on June 5, 2026 at 1:30 pm

    You don’t need to convert a date to a string in order to send it to SQL Server.

    Instead of all this:

    string cd1, date1;
    cd1 = System.DateTime.Today.ToShortDateString();
    date1 = Convert.ToDateTime(cd1).ToString("dd/MM/yyyy");
    cmd.Parameters.AddWithValue("@cd", date1.ToString());
    

    Just do this:

     cmd.Parameters.AddWithValue("@cd", DateTime.Today);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a code to read a file, store it in a structure
So I have no code at the current time but I haven't quite started
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written code to perform a function that could take a while to
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have written some code for playing a .wav through my application. Now I
I have written this code to join ArrayList elements: Can it be optimized more?
I have written some code to ensure that items on an order are all
I have written some code to look at properties using reflection. I have retrieved

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.