Command Objects and strings!

Results 1 to 2 of 2

Thread: Command Objects and strings!

  1. #1
    Join Date
    Dec 1969

    Default Command Objects and strings!

    I have a page that passes a variables as a string to a second page. The second page uses the following code to execute a stored procedure which parses the string data, and forms a select statement out of it.<BR><BR>&#060;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&#062;<BR>&#060;!--#include file="Connections/svrsql.asp" --&#062;<BR>&#060;%<BR><BR>Dim Command1__BuildingID<BR>Command1__BuildingID = ""<BR>if(Request("BuildingID") &#060;&#062; "") then Command1__BuildingID = Request("BuildingID")<BR><BR>Dim Command1__StartDate<BR>Command1__StartDate = "200302"<BR>if((Request("StartYear") & Request("StartMon")) &#060;&#062; "") then Command1__StartDate = (Request("StartYear") & Request("StartMon"))<BR><BR>Dim Command1__EndDate<BR>Command1__EndDate = "200306"<BR>if((Request("EndYear") & Request("EndMon")) &#060;&#062; "") then Command1__EndDate = (Request("EndYear") & Request("EndMon"))<BR><BR>%&#062;<BR>&#060;%<BR><B R>set Command1 = Server.CreateObject("ADODB.Command")<BR>Command1.A ctiveConnection = MM_svrsql_STRING<BR>Command1.CommandText = "MRI_USER.sp_viiGetCashFlowAccounts2"<BR>Command1. Parameters.Append Command1.CreateParameter("@RETURN_VALUE", 3, 4)<BR>Command1.Parameters.Append Command1.CreateParameter("@BuildingID", 129, 1,50,Command1__BuildingID)<BR>Command1.Parameters. Append Command1.CreateParameter("@StartDate", 129, 1,6,Command1__StartDate)<BR>Command1.Parameters.Ap pend Command1.CreateParameter("@EndDate", 129, 1,6,Command1__EndDate)<BR>Command1.CommandType = 4<BR>Command1.CommandTimeout = 0<BR>Command1.Prepared = true<BR>set rsData = Command1.Execute<BR>rsData_numRows = 0<BR><BR>%&#062;<BR><BR><BR><BR><BR>I know the stored procedure is working correctly because when I run it in SQL query analyzer, it works perfectly. Also, my second page works correctly when I only pass 1 item in the string. It&#039;s only when I try to pass more than 1 item via the string (i.e. &#039;Building1,Building2&#039;), that I get an error. The error I am recieving is:<BR><BR>Microsoft OLE DB Provider for ODBC Drivers (0x80040E57)<BR>[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated.<BR>/custommri/CashFlowsCalcBeta.asp, line 30<BR><BR>Note: Line 30 is the line with set rsData = Command1.Execute on it. My question is, why is the data being truncated? ...and how can I keep it from being truncated?<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Heard of DEBUG?

    How about you Response.Write all 3 parameter values *BEFORE* you start using them?<BR><BR>You have very bogus code in there, you know:<BR><BR>if((Request("StartYear") & Request("StartMon")) &#060;&#062; "") <BR><BR>That says "if either the form&#039;s StartYear or the StartMon field is non-blank, then use the concatenation of the two as the value of Command1_StartDate."<BR><BR>For example, if Request("StartYear") is blank, but Request("StartMon") is 3, then you will set Command1_StartDate to "3".<BR><BR>Unless you are using JS code in the form to ensure otherwise, I don&#039;t see how that code is guaranteed to get you a valid StartDate value, at all.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts