Solved

Trouble with inserting into SQL database

Posted on 2008-10-17
6
258 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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…

717 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