?
Solved

Trouble with inserting into SQL database

Posted on 2008-10-17
6
Medium Priority
?
262 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 13

Accepted Solution

by:
AielloJ earned 2000 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

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, we’ll look at how to deploy ProxySQL.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

762 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