CFF KB - Carrz-Fox-Fire Promotions Knowledge Base
CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.Knowledge Base
- Breadrumbs:
Microsoft OLE DB Provider for SQL Server (0x80040E07) Conversion failed when converting the varchar value 'myusername' to data type int (or) The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
- Article ID:
82 - Date Created
Tuesday, December 28, 2010 - Last Updated
Tuesday, March 15, 2011 - This Article Has been Viewed
3899 times - Short Desc
When creating your SQL Select Query statement, you will sometimes use the wrong column for your Query, this will result in the following error. This can also happen if you try to insert text into a datetime column. - Details
Creating your SQL Select Query, you sometimes use the wrong Column (or) wrong variable.
When this happens, you get the following error.
Scenario #1:Microsoft OLE DB Provider for SQL Server (0x80040E07)
Conversion failed when converting the varchar value 'myusername' to data type int.
/Header.asp, line 39
Scenario #2:Microsoft OLE DB Provider for SQL Server error '80040e07'
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
/logout.asp, line 17 - Recreate Issue
To recreate this issue:
Scenario #1:<%
myVal = ProtectSQL(request.querystring("id"))
sql.commandtext="select colnum, coltext, coltext from table1 where coltext=?"
sql.Parameters.Append sql.CreateParameter("@colnum", adInteger, adParamInput, , myVal)
%>
In the above example, we have our coltext which is of data type varchar as are Column to use for our Query, but in our Parameter we are using our colnum which is an integer
Scenario #2:<%
myVal = ProtectSQL(request.querystring("id"))
sql.commandtext="update table1 set uDate=? where id=?"
sql.Parameters.Append sql.CreateParameter("@LoggedTime", advarchar, adParamInput, 50, date()&" - "&time())
sql.Parameters.Append sql.CreateParameter("@id", adInteger, adParamInput, , myVal)
%>
In the above, the code is correct, but the database column for LoggedTime was set to data type datetime. - Resolve Issue
To correct this issue.
Scenario #1:<%
myVal = ProtectSQL(request.querystring("id"))
sql.commandtext="select colnum, coltext, coltext from table1 where colnum=?"
sql.Parameters.Append sql.CreateParameter("@colnum", adInteger, adParamInput, , myVal)
%>
As you can see here, we have removed the coltext and replaced it with the correct column of colnum, this corresponds with parameter and the variable that we have created.
Scenario #2:<%
myVal = ProtectSQL(request.querystring("id"))
sql.commandtext="update table1 set uDate=? where id=?"
sql.Parameters.Append sql.CreateParameter("@LoggedTime", advarchar, adParamInput, 50, date()&" - "&time())
sql.Parameters.Append sql.CreateParameter("@id", adInteger, adParamInput, , myVal)
%>
In the database, we set the LoggedTime's data type to VarChar(50)
This is the changed that needed to take place in order for this code to work.
Share With Friends (Updated 6-8-2010)
Recent Articles
All Topics
- Coming Soon - Knowledge Exchange
Trending Articles
- Microsoft VBScript runtime error '800a0046' Permission denied FileSystemObject 24695
- Microsoft OLE DB Provider for SQL Server error '80040e57' String or binary data would be truncated. or The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data. 21297
- ADODB.Parameters error '800a0e7c' Parameter object is improperly defined 19544
- After Effects warning: Audio conforming failed for the following file .cfa. Perhaps due to disk space 17785
- The backup set holds a backup of a database other than the existing 16826