2012-03-28 78 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