0

I can execute the query in SQL Management Studio successfully. ASP code throws an error.

        Response.Write "<hr>" & sql & "<hr>"            
        conn3.Execute sql

ASP Error:

Microsoft OLE DB Provider for SQL Server hata '80040e07'

Error converting data type varchar to smalldatetime.

SQL query:

exec db.dbo.stored_proc1 @artID='6226', 
  @Odeme_Date='3-27-2013 15:47:24', @Odeme_Valor ='3-27-2013', 
  @OnceAnapara=0, @GecZamHemen= 1, @ODENEN_TUTAR = '263.69' , 
  @Odeme_Tip=3, @BankID=62, @MakbuzTanimID=45, @BilinmeyenID=NULL, 
  @CariAvansID=NULL, 
  @USERID=62, @MakbuzNO=NULL, @SelectedID='(817843)', 
  @Mesaj=NULL, @idleriGosterme=0, @CariCekID=NULL, 
  @CariSenetID=NULL

I can copy & paste the query then execute it successfully. What's wrong with ASP?

4

3 回答 3

2

我使用了参数化查询并且它有效。

此链接有助于查找数据类型值:http ://www.w3schools.com/ado/ado_datatypes.asp

PS:不要使用@Var_Date的查询字符串版本;即“MM-DD-YYYY”作为参数化输入。使用“YYYY-MM-DD”格式的参数。

于 2013-03-28T07:52:35.413 回答
1

错误来自提供者,所以它确实看到了数据类型不匹配。它可能在 SQL Server Management Studio 中运行,但在提供程序中仍然失败。我会再次查看日期文字并尝试更改日期格式,看看你是否可以让它工作。

如果提供者根本不传递 varchar,那么您可能必须重新连接存储过程以接受 varchar 参数,并将它们转换为过程中的日期类型。

于 2013-03-27T14:55:00.893 回答
0

I suspect it has something to do with your server settings regarding date formats (from your parameter names, looks like you are probably not using USA date formatting). Try checking your "dateformat" on the target database:

use db
go

DBCC USEROPTIONS

Regardless, you should always format date strings in one of the "unambiguous" formats: YYYYMMDD or YYYY-MM-DD. So I would change the date parameter string values:

@Odeme_Date='2013-03-27 15:47:24', @Odeme_Valor ='2013-03-27'
于 2013-03-27T14:46:23.193 回答