Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I load values of combo boxes here........
I dont want to set listindex property to -1

VB
Private Sub Form_Load()
OPENCON

RES.Open "DIVISION", CON, adOpenDynamic, adLockOptimistic, adCmdTable
    If RES.RecordCount > 0 Then
        RES.MoveFirst
            For i = 0 To RES.RecordCount - 1
                CmbDiv.AddItem RES.Fields("DIV").Value
                CmbDiv.ItemData(CmbDiv.NewIndex) = RES.Fields("DIVID").Value
        RES.MoveNext
    Next
    End If

RES.Open "HNM", CON, adOpenDynamic, adLockOptimistic, adCmdTable
    If RES.RecordCount > 0 Then
        RES.MoveFirst
            For i = 0 To RES.RecordCount - 1
CmbHouse.AddItem Trim(RES.Fields("HOUSE").Value)
     CmbHouse.ItemData(CmbHouse.NewIndex) = RES.Fields("HID").Value
        RES.MoveNext
        Next
    End If

This is the code I used to modify record.........
VB
Private Sub CmdSave_Click()
  1.  sql = "UPDATE STUDENT_RECORD_DATABASE SET "
  2.  sql = sql + "ROLLNO= " & Val(CmbRNO) & ","
  3.  sql = sql + "DIVID='" & Val(CmbDiv.ItemData(CmbDiv.ListIndex)) & "',"
  4.  sql = sql + "HID=" & Val(CmbHouse.ItemData(CmbHouse.ListIndex)) & " "
  5.  sql = sql + "WHERE ROLLNO= " & Val(CmbRNO) & ""
Set RES = CON.Execute(sql)
End Sub


While running this code If I modify both division and house then it's ok......
but when I let any one value of them(doesn't modify value) it shows error :

Invalid Property array value at 3rd and 4th line
Please help.......
Posted
Updated 4-Feb-13 1:35am
v2

1 solution

You need to perform further validation on the data before trying to manipulate it into the constructed SQL statement.

You should also not use constructed statement like this as it could lead to SQL injection issues. Use parameter based queries.
 
Share this answer
 
Comments
surkhi 5-Feb-13 0:08am    
Sir,I don't understand what you are trying to say....
Please specify via code....
Thanx
surkhi 5-Feb-13 0:16am    
I made one procedure and call it before
sql = sql + "DIVID='" & Val(CmbDiv.ItemData(CmbDiv.ListIndex))&"',"


Private Sub lIndex()
Dim t As String
t = CmbFulNM.Text
If CmbDiv.ListIndex = -1 Then
If Len(Trim(t)) > 0 Then
For i = 0 To CmbDiv.ListCount - 1
If (CmbDiv.List(i)) = t Then
CmbDiv.ItemData(CmbDiv.ListIndex) = i
End If
Next i
End If
End If
End Sub
surkhi 5-Feb-13 0:17am    
Then also it shows same error,what sh'd I do???
DaveAuld 5-Feb-13 1:49am    
You need to be understanding why it throws errors, I suspect you are still not putting valid data into the SQL, or the VAL statements are failing because they have invalid data to evaluate. VAL is very picky. Also do a search for SQL Parameter queries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900