Solved

Trouble with inserting into SQL database

Posted on 2008-10-17
6
253 Views
Last Modified: 2013-11-26
Hello

I created a web site that my users will be able to put in trouble tickets to. Part of this is the date and time they put it in and then the date and time the tech got back to them and then the Resolution date. I need to be able to do a date difference between them. but when I make the SQL database a date field I get a error when I submit the page. The error is as follows. Help would be greatly appreciated.

Error inserting record. Syntax error converting datetime from character string.  

0
Comment
Question by:riley00
6 Comments
 
LVL 9

Expert Comment

by:Gianpiero Rossi
ID: 22741306
can you submit the SQL String  that you use for the insert
0
 

Author Comment

by:riley00
ID: 22741341
insertSQL = "INSERT INTO dbo.FinMain (";
        insertSQL += "StartDate, Vzid, FName, LName, Location, Phone, MachineName, Problem, ResolutionDate) ";
        insertSQL += "VALUES ('";
        insertSQL += DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString() + "', '";
        insertSQL += txtBoxVZID.Text + "', '";
        insertSQL += txtBoxFName.Text + "', '";
        insertSQL += txtBoxLName.Text + "', '";
        insertSQL += ddlLocation.SelectedItem + "', '";
        insertSQL += txtBoxPhone.Text + "', '";
        insertSQL += txtBoxMachName.Text + "', '";
        insertSQL += ddlProblem.SelectedItem + "', '";
        insertSQL += "0" + "')";
0
 
LVL 9

Expert Comment

by:Gianpiero Rossi
ID: 22741386
try in this way

insertSQL = "INSERT INTO dbo.FinMain (";
        insertSQL += "StartDate, Vzid, FName, LName, Location, Phone, MachineName, Problem, ResolutionDate) ";
        insertSQL += "VALUES ('";
        insertSQL += DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString().Replace(".",":") + "', '";
        insertSQL += txtBoxVZID.Text + "', '";
        insertSQL += txtBoxFName.Text + "', '";
        insertSQL += txtBoxLName.Text + "', '";
        insertSQL += ddlLocation.SelectedItem + "', '";
        insertSQL += txtBoxPhone.Text + "', '";
        insertSQL += txtBoxMachName.Text + "', '";
        insertSQL += ddlProblem.SelectedItem + "', '";
        insertSQL += "0" + "')";
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Accepted Solution

by:
AielloJ earned 500 total points
ID: 22741637
I believe the issue is caused when the value "0" is inserted into a table column that is defined as a Date/Time type.  It probably can't convert the "0" string to a valid date.  If that is the case, you may want to alter the table definition to allow NULL's in the ResolutionDate column.

[ResolutionDate] [datetime] NULL

When the issue is resolved, you'd run your UPDATE SQL statement that will replace the null value in ResolutionDate with a date value.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22741767
If you are inserting new records, is it not the case that there is no Resolution date for that new record?  If that is true, then simply do NOT assign a resolutionDate value (see below)
as suggested above, allow the ResolutionDate field to accept a NULL, and you should be 'good to go'
 
AW
 
 

insertSQL = "INSERT INTO dbo.FinMain (";

        insertSQL += "StartDate, Vzid, FName, LName, Location, Phone, MachineName, Problem) ";

        insertSQL += "VALUES ('";

        insertSQL += DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString().Replace(".",":") + "', '";

        insertSQL += txtBoxVZID.Text + "', '";

        insertSQL += txtBoxFName.Text + "', '";

        insertSQL += txtBoxLName.Text + "', '";

        insertSQL += ddlLocation.SelectedItem + "', '";

        insertSQL += txtBoxPhone.Text + "', '";

        insertSQL += txtBoxMachName.Text + "', '";

        insertSQL += ddlProblem.SelectedItem + "')";

Open in new window

0
 

Author Closing Comment

by:riley00
ID: 31507149
This was causing me error, thanks to all who reponded.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now