473,666 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDateTime overflow - ASP.net 2.0 C#

1 New Member
I am having this kind of error when trying to insert a null value;

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

bellow is my code, thanks

protected void btnAddTime_Clic k(object sender, EventArgs e)
{
try
{
string timeNum = txtTimeControlN um.Text;
string dateCreated = DateTime.Today. ToShortDateStri ng();
string createdby = System.Web.Http Context.Current .User.Identity. Name;
DateTime requestedOn = txtrequestedOn. SelectedDate;
DateTime serviceDate = txtserviceDate. SelectedDate;

string customerID = ddlCust.Selecte dValue;
string employeeID = ddlEmp.Selected Value;
string hourIn = txthourIn.Text;
string hourOut = txthourOut.Text ;
string place = txtPlace.Text;
string jobDesc = txtJobdesc.Text ;
string materials = txtMaterials.Te xt;
string comments = txtComments.Tex t;
string travelTime = txtTravelTime.T ext;
string laborHour = txtLaborhours.T ext;

string insertTime = "INSERT into wd_tblTimesheet (wd_timeControl Num, wd_tsDateCreate d, wd_tsBy, wd_servReqOn, wd_tsServiceDat e, wd_custID, wd_empID, wd_tsHourIn, wd_tsHourOut, wd_tsPlace, wd_tsJobDesc, wd_tsMaterials, wd_tsComments, wd_tsTravelTime , wd_tsLaborHour) ";
insertTime += " values ('";
insertTime += timeNum;
insertTime += "', '" + dateCreated;
insertTime += "', '" + createdby;
insertTime += "', '" + requestedOn;
insertTime += "', '" + serviceDate;
insertTime += "', '" + customerID;
insertTime += "', '" + employeeID;
insertTime += "', '" + hourIn;
insertTime += "', '" + hourOut;
insertTime += "', '" + place;
insertTime += "', '" + jobDesc;
insertTime += "', '" + materials;
insertTime += "', '" + comments;
insertTime += "', '" + travelTime;
insertTime += "', '" + laborHour;
insertTime += "' )";

string conn = @"server=FMWEB; database=servCo ntrol;uid=sa;pw d=sa";
System.Data.Sql Client.SqlConne ction myconn = new SqlConnection(c onn);

System.Data.Sql Client.SqlComma nd myCommand = new SqlCommand();
myCommand = new SqlCommand(inse rtTime, myconn);

myconn.Open();

myCommand.Param eters.Add("@wd_ timeNumControl" , SqlDbType.VarCh ar, 10).Value = timeNum;
myCommand.Param eters.Add("@wd_ tsDateCreated", SqlDbType.DateT ime, 8).Value = dateCreated;
myCommand.Param eters.Add("@wd_ tsBy", SqlDbType.VarCh ar, 60).Value = createdby;
myCommand.Param eters.Add("@wd_ servReqOn", SqlDbType.DateT ime,8).Value = requestedOn;
myCommand.Param eters.Add("@wd_ tsServiceDate", SqlDbType.DateT ime, 8).Value = serviceDate;
myCommand.Param eters.Add("@wd_ custID", SqlDbType.Int, 4).Value = customerID;
myCommand.Param eters.Add("@wd_ empID", SqlDbType.Int, 4).Value = employeeID;
myCommand.Param eters.Add("@wd_ tsHourIn", SqlDbType.VarCh ar, 20).Value = hourIn;
myCommand.Param eters.Add("@wd_ tsHourOut", SqlDbType.VarCh ar, 20).Value = hourOut;
myCommand.Param eters.Add("@wd_ tsPlace", SqlDbType.VarCh ar, 70).Value = place;
myCommand.Param eters.Add("@wd_ tsJobDesc", SqlDbType.VarCh ar, 5000).Value = jobDesc;
myCommand.Param eters.Add("@wd_ tsMaterials", SqlDbType.VarCh ar, 5000).Value = materials;
myCommand.Param eters.Add("@wd_ tsComments", SqlDbType.VarCh ar, 5000).Value = comments;
myCommand.Param eters.Add("@wd_ tsTravelTime", SqlDbType.VarCh ar, 20).Value = travelTime;
myCommand.Param eters.Add("@wd_ tsLaborHour", SqlDbType.VarCh ar, 50).Value = laborHour;

myCommand.Execu teNonQuery();

myconn.Close();

this.lblMessage .Text = "New Timesheet Added.";

//Response.Redire ct("panel.aspx" );

}

catch (Exception ex)
{

lblMessage.Text = ex.Message;


}
Jan 9 '07 #1
1 3939
kenobewan
4,871 Recognized Expert Specialist
You might try using a # either side of the time... e.g "#" + traveltime + "#", when inserting.

Hope that this helps.
Jan 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7966
by: FrodoBaggins | last post by:
Dear Team, Attempting to insert a record into a SQL database, using the command: command.ExcuteNonQuery(); Get the following error message in the event log: SQLDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
2
2620
by: damon.f | last post by:
I've got a classic ASP application that I'm migrating to .NET. In the client script we used to use the following code to help build up the sql string. It converted a text date to the SQL Server Date format. sSQL = sSQL + SQLServerDate(Request.Form ("PLANNEDEXITDATE")) + "," I'm now trying to do this server side in VB.NET but I can't seem to find a way to do it using convert or
1
1373
by: poppy | last post by:
I set up my parameters in code as follows : lTTState.startDate = Today.AddDays(-10) lTTState.startDate = Today lSqlCmd.Parameters.Add(New SqlParameter("@startDate", SqlDbType.DateTime)) lSqlCmd.Parameters("@startDate").Value = lTTState.startDate lSqlCmd.Parameters.Add(New SqlParameter("@endDate", SqlDbType.DateTime)) lSqlCmd.Parameters("@endDate").Value = lTTState.endDate
1
2045
by: Paperback Writer | last post by:
I need to insert null in a DateTime field and in the ASP.Net i got this error: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. How to accomplish that ? -- Please, check my theSpoke: http://www.thespoke.net/MyBlog/dgroh/MyBlog.aspx
5
35224
by: mlafarlett | last post by:
Alright..I've found lots of info on this error and most say assign System.DBNull.Value, System.Convert.DBNull, or System.Data.SqlTypes.SqlDateTime.Null to my stored proc param and the problem will be solved...NOT. I suspect all of these are the same thing, however, none solve my problem. What I have is vb.net code trying to put a null in a sql2000 datatime field. To further confuse things, it works on my PC and not from another. I...
3
2129
by: Mike9900 | last post by:
Hello, I am getting SqlDateTime overflow if I use .NET remoting on Windows XP and Windows XP is the server where the SQL server is located at. If my computer is Windows 2003 where the sql server is running and I use client as the windows XP I do not get this error. -- Mike
3
1760
by: baburk | last post by:
HI I want to pass null or "" When I pass like that I got an error System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. Is there is any possibility to send null or ""
4
3927
by: jhansi xavier | last post by:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
0
2804
by: maolimix | last post by:
Hi to all, I have a trouble with datetime...now I explain.. I must to store to a C# variable the values from a "Datetime column" of Sql Server 2005. I tried 3 methods ...in the first two I never was able to get the Millisecond from datacolumn. I explain the methods... 1) I created a Datatable that contain the column... then I fill a datarow with the current value. The system automatically converts the Sqldatetime in System.Datetime but...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.