Solved

Trouble with inserting into SQL database

Posted on 2008-10-17
6
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

730 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