Solved

Trouble with inserting into SQL database

Posted on 2008-10-17
6
254 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now