Systax error in my code, Please help me. [Resolved]

Posted by Nuwan under ASP.NET on 11/18/2012 | Points: 10 | Views : 1199 | Status : [Member] | Replies : 3
I write this code for insert checklistbox value in database.

Dim qry As String = ""
Dim usr As String = "nuwan"

Dim list As ListItem

For Each list In CheckBoxList1.Items
If (list.Selected) Then

qry += "insert into privilage (user,page) values('" + usr + "','" + list + "')"

End If

Next

If (qry <> "") Then

Dim sqlcmd As SqlCommand = New SqlCommand(qry, sqlcon)
sqlcmd.CommandType = CommandType.Text
sqlcon.Open()
sqlcmd.ExecuteNonQuery()
sqlcon.Close()

End If


I got following error. how I fix it.Please help me

error BC30452: Operator '+' is not defined for types 'String' and 'System.Web.UI.WebControls.ListItem'.

Rathnayake


Responses

Posted by: Krv on: 11/19/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
qry += "insert into privilage (user,page) values('" + usr + "','" + list + "')" 


In the above code, list is the list is 'System.Web.UI.WebControls.ListItem' object. So u cant concatinate string this listitem
You should try,
qry += "insert into privilage (user,page) values('" + usr + "','" + list.Value + "')" 



Thanks,
R.Vasanth
MCTS(SQL Server & BI)
http://bigdatatech.blogspot.com

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nuwan on: 11/19/2012 [Member] Starter | Points: 25

Up
0
Down
Its work........... Nice


Rathnayake

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 11/19/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
once try this one, remove + after qry

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response