473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

SqlDateTime overflow - ASP.net 2.0 C#

1
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_Click(object sender, EventArgs e)
{
try
{
string timeNum = txtTimeControlNum.Text;
string dateCreated = DateTime.Today.ToShortDateString();
string createdby = System.Web.HttpContext.Current.User.Identity.Name;
DateTime requestedOn = txtrequestedOn.SelectedDate;
DateTime serviceDate = txtserviceDate.SelectedDate;

string customerID = ddlCust.SelectedValue;
string employeeID = ddlEmp.SelectedValue;
string hourIn = txthourIn.Text;
string hourOut = txthourOut.Text;
string place = txtPlace.Text;
string jobDesc = txtJobdesc.Text;
string materials = txtMaterials.Text;
string comments = txtComments.Text;
string travelTime = txtTravelTime.Text;
string laborHour = txtLaborhours.Text;

string insertTime = "INSERT into wd_tblTimesheet(wd_timeControlNum, wd_tsDateCreated, wd_tsBy, wd_servReqOn, wd_tsServiceDate, 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=servControl;uid=sa;pwd=sa" ;
System.Data.SqlClient.SqlConnection myconn = new SqlConnection(conn);

System.Data.SqlClient.SqlCommand myCommand = new SqlCommand();
myCommand = new SqlCommand(insertTime, myconn);

myconn.Open();

myCommand.Parameters.Add("@wd_timeNumControl", SqlDbType.VarChar, 10).Value = timeNum;
myCommand.Parameters.Add("@wd_tsDateCreated", SqlDbType.DateTime, 8).Value = dateCreated;
myCommand.Parameters.Add("@wd_tsBy", SqlDbType.VarChar, 60).Value = createdby;
myCommand.Parameters.Add("@wd_servReqOn", SqlDbType.DateTime,8).Value = requestedOn;
myCommand.Parameters.Add("@wd_tsServiceDate", SqlDbType.DateTime, 8).Value = serviceDate;
myCommand.Parameters.Add("@wd_custID", SqlDbType.Int, 4).Value = customerID;
myCommand.Parameters.Add("@wd_empID", SqlDbType.Int, 4).Value = employeeID;
myCommand.Parameters.Add("@wd_tsHourIn", SqlDbType.VarChar, 20).Value = hourIn;
myCommand.Parameters.Add("@wd_tsHourOut", SqlDbType.VarChar, 20).Value = hourOut;
myCommand.Parameters.Add("@wd_tsPlace", SqlDbType.VarChar, 70).Value = place;
myCommand.Parameters.Add("@wd_tsJobDesc", SqlDbType.VarChar, 5000).Value = jobDesc;
myCommand.Parameters.Add("@wd_tsMaterials", SqlDbType.VarChar, 5000).Value = materials;
myCommand.Parameters.Add("@wd_tsComments", SqlDbType.VarChar, 5000).Value = comments;
myCommand.Parameters.Add("@wd_tsTravelTime", SqlDbType.VarChar, 20).Value = travelTime;
myCommand.Parameters.Add("@wd_tsLaborHour", SqlDbType.VarChar, 50).Value = laborHour;

myCommand.ExecuteNonQuery();

myconn.Close();

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

//Response.Redirect("panel.aspx");

}

catch (Exception ex)
{

lblMessage.Text = ex.Message;


}
Jan 9 '07 #1
1 3918
kenobewan
4,871 Expert 4TB
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
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...
2
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...
1
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))...
1
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 ?...
5
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...
3
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...
3
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...
4
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.