2012-03-28 139 views
0

使用更新的阵列,这是我现有的代码:在Visual Basic

DBConn.BeginTrans 
        strSQL = "DELETE tblAvailable WHERE " 
     strSQL = strSQL + "(intResortID = " + Session("TypeID") + ")" 
     strSQL = strSQL + " AND (dtm BETWEEN CONVERT(DATETIME,'" + cstr(Year(dtmStart)) + "-" + cstr(Month(dtmStart)) + "-" + cstr(Day(dtmStart)) + "', 102)" 
     strSQL = strSQL + " AND CONVERT(DATETIME,'" + cstr(Year(dtmEnd)) + "-" + cstr(Month(dtmEnd)) + "-" + cstr(Day(dtmEnd)) + "', 102))" 


     'SY SINGH 
     'Add code to only delete out room types contained in the spreadsheet 
     Dim i 
     strSQL = strSQL & "AND (strRoomType='" & strRooms(0) & "'" 
     For i = 1 to m_Rooms 
      strSQL = strSQL & " OR strRoomType='" & strRooms(i) & "'" 
     next 
     strSQL = strSQL & ")" 

我想改变它做一个更新替代,设置curprice其中strRoomType等于房间的阵列。

这就是我来了这么远

strSQL = "Update tblAvailable set curprice ="+ FixNumber(curprice (intCurrentData)) 
    response.Write(strSQL) 
    strSQL = strSQL +"WHERE intResortID = " + Session("TypeID") 
    response.Write(strSQL) 
    strSQL = strSQL + " AND dtm BETWEEN CONVERT(DATETIME,'" + cstr(Year(dtmStart)) + "-" + cstr(Month(dtmStart)) + "-" + cstr(Day(dtmStart)) + "', 102)" 
    response.Write(strSQL) 
    strSQL = strSQL + " AND CONVERT(DATETIME,'" + cstr(Year(dtmEnd)) + "-" + cstr(Month(dtmEnd)) + "-" + cstr(Day(dtmEnd)) + "', 102)" 
    response.Write(strSQL) 
    dim i 

    strSQL = strSQL + " AND (strRoomType='" & strRooms(0) & "'" 
    response.Write(strSQL) 
    For i = 1 to m_Rooms 
    strSQL = strSQL & " OR strRoomType='" & strRooms(i) & "'" 
    response.Write(strSQL) 
    next 
    strSQL = strSQL & ")" 
    response.Write(strSQL) 

    DBConn.Execute strSQL 

这是我收到的错误:

dtm'dtm' OR strRoomType='obeqvb'dtm' OR strRoomType='obeqvb') 
Microsoft OLE DB Provider for SQL Server error '80040e14' 

Incorrect syntax near 'obeqvb'. 

/upload_excel_v3.asp, line 230 

obeqvb是我strr​​oomtype和DTM是我的约会

回答

2

你应该通过加倍你的价值来逃避任何单引号

'my'roomtype'my''roomtype'

而且你最好使用where strRoomType in(...),而不是“或”

+0

通过这样做,我能找到真正的Bug是在被上传到ASP页Excel表格。感谢那! – user1270384 2012-03-28 22:05:07