Error = Arithmetic overflow error converting expression to data type smalldatetim

  $exception {"Arithmetic overflow error converting expression to data type smalldatetime.\r\nThe statement has been terminated."} System.Exception {System.Data.SqlClient.SqlException}

occurs Crying

here is my code

protected void EmailSubmitBtn_Click(object sender, EventArgs e)

{

SqlDataSource NewsletterSqlDataSource = new SqlDataSource();

NewsletterSqlDataSource.ConnectionString =

ConfigurationManager.ConnectionStrings["NewsletterConnectionString"].ToString();

 

//Text version

NewsletterSqlDataSource.InsertCommandType =

SqlDataSourceCommandType.Text;

NewsletterSqlDataSource.InsertCommand =

"INSERT INTO NewsLetter (EmailAddress, IPAddress, DateTimeStamp) VALUES (@EmailAddress, @IPAddress, @DateTimeStamp)";

 

//storeprocedure version

//NewsletterSqlDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;

//NewsletterSqlDataSource.InsertCommand = "EmailInsert";

NewsletterSqlDataSource.InsertParameters.Add(

"EmailAddress", EmailTb.Text);

NewsletterSqlDataSource.InsertParameters.Add(

"IPAddress", Request.UserHostAddress.ToString());

NewsletterSqlDataSource.InsertParameters.Add(

"DateTimeStamp", DateTime.Now.ToString());

int rowsAffected = 0;

try

{

rowsAffected = NewsletterSqlDataSource.Insert();

}

catch (Exception ex)

{

Server.Transfer(

"NewsletterProblem.aspx");

}

finally

{

NewsletterSqlDataSource =

null;

}

if (rowsAffected != 1)

{

Server.Transfer(

"NewsletterProblem.aspx");

}

else

{

Server.Transfer(

"NewsletterSuccess.aspx");

}


 
2
Websta4
3/23/2007 3:07:32 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies
4446 Views

Similar Articles

[PageSpeed] 26

Do not pass the Value as DateTime.Now.ToString() . Just pass the value as DateTime.Now if the db datatype is smalldatetime. If the input datatype for stored procedure is string , try 

DateTime

.Now.ToShortDateString(); . Let me know if you need any clarifications

Ashok Raja
www.iGold.in

Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved.
0
AshokRaja
3/23/2007 5:34:43 AM

I had the same problem and the only thing that come in my brains is that my computer has a different date display so, when I try to retrieve the date, it comes without the AM/PM.

I tryed many conversion types and none of them seem to solve the problem.

My system is 24hs and don't have the AM/PM system.

So, I solved the problem with this:
BEFORE converting it to Stored Procedure

string AmericanDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss");

if (DateTime.Now.Hour >= 12)
{
    AmericanDate +=
" PM";
}
else
{
    AmericanDate +=
" AM";
}

DataSource.InsertParameters.Add("DateTimeStamp", AmericanDate);

 

After this you can continue your coding normally.

I hope that helps you.Wink

0
Capiel
3/18/2008 11:59:57 AM

 Why pass the DateTimeStamp stamp to the database? You can use GetDate() or GetUTCDate() within your TSQL to get it from the database server.

so

"INSERT INTO NewsLetter (EmailAddress, IPAddress, DateTimeStamp) VALUES (@EmailAddress, @IPAddress, @DateTimeStamp)";

would become

"INSERT INTO NewsLetter (EmailAddress, IPAddress, DateTimeStamp) VALUES (@EmailAddress, @IPAddress, GetDate())";

You can of course make  DateTimeStamp a non-null coulmn with a default value of GetDate(), in which case your insert simplifies to:

"INSERT INTO NewsLetter (EmailAddress, IPAddress) VALUES (@EmailAddress, @IPAddress)";

(If you use GetUTCDate() the date-time in Universal (GMT) will be used.)


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
TATWORTH
3/18/2008 12:13:33 PM
Reply:

Similar Artilces:

SQL Server Error: "Arithmetic overflow error converting numeric to data type numeric"
I'm still quite new to SQL, and so I may be missing something quite obvious. Apologies in advance if that's the case. I've included my query at the bottom of the message as it is quite long; my problem is that I get "Arithmetic overflow error converting numeric to data type numeric" when the first parameter to my COALESCE calls is not NULL. That is, the COALESCEs and the query work as I expect when SUM(cust_vw_actual.Actual) is NULL (they return 0.00), but if it isn't I get the error. I am also getting "Warning: Null value eliminated from aggregate.&...

Trying to convert column from datatype nvarchar to datetime
Hi All,  I am trying to simply change a column from a datatype of nvarchar to a datetime datatype.  However when I do I receive the following error message: " Arithmetic overflow error converting expression to data type datetime."To note there is already a date filled out in the columns which I presume the reason why the error is reporting?! however for some reason when originally setup datetime was not used but rather nvarchar to capture the data.The format is: 16/01/2007 09:53:50 There are around 24000 entries that I need converting somehow so if anyone can help...

Arithmetic overflow error converting expression to data type datetime.
Hi. My query below executes perfectly in SQL query analyzer.SELECT     pre_e.......... recruitment_advertising.advertising_date, career_details.RTS_Email, datediff(d,Cast(recruitment_advertising.advertising_date as DATETIME),CAST(career_details.RTS_Email as Datetime)) as Ad_to_RTS_daysFROM         pre_employee INNER JOIN..........advertising_date is of type nvarchar and so is RTS_EmailThey ARE in the format dd/mm/yyyy  (GB format).But when I create a dataset and  objectdatasource using the same query to use in the reportvi...

Arithmetic overflow error converting expression to data type datetime
Hi,I don't know why I'm still having this error even if the only part that deals with the date fields are only using getdate() function.SQL Server Database Error: Arithmetic overflow error converting expression to data type datetime.The statement has been terminated.Many Thanks & Best Regards,HuaMin Chen(Mark it as answer if it does help you!)  Can you post your code to get understanding of your problem clearyly.  Thanks,santosh_maharajaPlease mark as answer if you got expected solution. wmec:SQL Server Database Error: Arithmetic overflow error converting expressi...

Arithmetic overflow error converting expression to data type datetime
Hi, I have the problem stated Arithmetic overflow error converting expression to data type datetime...  I have little idea on y the error occur...Need help asap if possible... suggestions , ideas My sql server 2000 database has the table custTransaction and some field name... dateOfPurchase is the field name in the table that i store the date format as nvarchar and in the format of dd/MM/yyyy... because does not have value larger den 12 there4 this error occur when i try retrieve data from database... Q: My qns is how can i dun change the format of my dateOfPurchase and retrieve ...

Arithmetic overflow error converting expression to data type datetime.
I have the error message:Arithmetic overflow error converting expression to data type datetime. when i click this button:    protected void Button2_Click(object sender, EventArgs e)    {         Int32 ProductId = Convert.ToInt32(Request.QueryString["proID"]);        bool result = Executeupdateclickedin(ProductId);        result = Executedeleteshipping(ProductId);        result = Executemassmail2(ProductId);&nb...

Arithmetic overflow error converting expression to data type datetime
Hi all,In the beginning of this month I've build a website with a file-upload-control. When uploading a file, a record (filename, comment, datetime) gets written to a SQLExpress database, and in a gridview a list of the files is shown. On the 7th of September I uploaded some files to my website, and it worked fine. In the database, the datetime-record shows "07/09/2006 11:45". When I try to upload a file today, it gives me the following error: Error: Arithmetic overflow error converting expression to data type datetime. The statement has been ...

Re: Arithmetic overflow error converting expression to data type datetime
I have a sql server 2000 database...using vb.net 2005... I have a form which allow user to find outstanding transaction by month selected in dropdownlist... If it matches the month it will populate out in datagrid, this date is store as dd/MM/yyyy... below is the following code:  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If ddl_payment.SelectedItem.Text = "Outstanding" Then ddl_months.Visible = True datagrid1.Visible = False If ddl_months.Visible = True...

Arithmetic overflow error converting expression to data type datetime #2
Hi, I'm having this error with my page, user picks the date -using the AJAX Control Toolkit Calender with the format of ( dd/MM/yyyy ). It looks like the application current format is MM/dd/yyyy, because it shows the error page if the day is greater than 12,  like: 25/03/2007 What is wrong? Here is the error page: Server Error in '/' Application. Arithmetic overflow error converting expression to data type datetime.The statement has been terminated. Description: An unhandled exception occurred during the execution of the current web request. Please review ...

Arithmetic overflow error converting expression to data type nvarchar.
Hi - I am a fairly new VB 2005 programmer.  I have a stored procedure, with a number of parameters, including "Monthly_Amount".   Here is the Stored Proc definitiion:   @Monthly_Day_Source nchar(2) = null,@Monthly_Amount_Source decimal(15,2) = null In the Stored Procedure and the ObjectDataSource associated with the Insert and Update Stored procedures, Monthly_Amount_Source is Decimal(15,2).    Monthly_Amount_Source is a parameter used by the Stored Procedures and does not exist in the database.  Detailsview shows:  <asp:Boun...

Arithmetic overflow error converting expression to data type int when using Fill from a SqlDataAdapter
I thought I'd post this quick problem and answer, as I couldn't find the answer when searching for it.  I tried to call a stored procedure on SQL Server 2000 using the System.Data.SqlClient objects, and was not expecting any unusual issues.  However when I came to call the Fill method I received the error "Arithmetic overflow error converting expression to data type int." My first checks were the obvious ones of verifying that I'd provided all the correct datatypes and had no unexpected null values, but I found nothing out of order.  The problem turns out to be a difference...

Stored Proc Error: error converting character string to smalldatetime data type
I am trying to create a page that adds users to a MS SQL database. In doing so, I have run into a couple errors that I can't seem to get past. I am hoping that I could get some assistance with them. Error from SQL Debug: --- Server: Msg 295, Level 16, State 3, Procedure AdminAddUser, Line 65 [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting character string to smalldatetime data type. --- Error from page execution: --- Exception Details: System.Data.OleDb.OleDbException: Error converting data type varchar to numeric. Source Error: Line 77...

Arithmetic overflow error converting float to data type numeric.
When this code executes, I am getting the error listed in the subject. The error is reported on the underlined and bold line. The values of the items are as follows: newTextName = SM1 newLat = 29.1878 newLong = 85.3417 newDescription = Test newCreator = John newCreate_Date = 9/14/2003 newDepth = 61 DropDownList2 = 7 'Get next Text_ID from Waypoint Table stmMaxSQL = "Select Max(WP_Text_ID) as WP_Text_ID From TBL_NM_Waypoint" objConn.Open() dadWaypoints = New SqlDataAdapter(stmMaxSQL, objConn) ...

Arithmetic overflow error converting varchar to data type numeric
Hello, i am getting "Arithmetic overflow error converting varchar to data type numeric"  while i am trying to cast the numeric value to varchar in SQL Server 2000(This is the Query  (cast(' + @Qty + ' as varchar(50)) If any knows plz help me, thanks.        "Arithmetic overflow error converting varchar to data type numeric" stands for error while converting varchar to numeric, and you say "trying to cast the numeric value to varchar", this is kind a confusing thing. Can you explain your problem more detailed?Nev...

Web resources about - Error = Arithmetic overflow error converting expression to data type smalldatetim - asp.net.sql-datasource

Resources last updated: 2/13/2016 9:20:08 AM