Problem setting a group of radio buttons from a dataset

G

greg

I'm trying to set a group of radio buttons based on the
value of a text field in a dataset. This is my code:

Dim ds As DataSet
ds = dtsVideo
Dim dt As DataTable = ds.Tables
("tblPeramItems")
Dim dr As DataRow = dt.Rows(0) 'first row in
datatable

If dr("strStockGroup") = "DVD" Then
rdbDVD.Checked = True
ElseIf dr("strStockGroup") = "Video" Then
rdbVideo.Checked = True
ElseIf dr("strStockGroup") = "Computer Game"
Then
rdbComputerGame.Checked = True
End If

This works as long as I have "Option Strict" set
to "Off". Otherwise i get the error "Option strict on
disallows operands of type object for operator '='.
Use the 'Is' operator to test for object Identity"

Unfortunately I am required to have "Option Strict" set
to "ON". Any ideas on how I can make this work?

Greg
 
A

Armin Zingler

greg said:
I'm trying to set a group of radio buttons based on the
value of a text field in a dataset. This is my code:

Dim ds As DataSet
ds = dtsVideo
Dim dt As DataTable = ds.Tables
("tblPeramItems")
Dim dr As DataRow = dt.Rows(0) 'first row in
datatable

If dr("strStockGroup") = "DVD" Then
rdbDVD.Checked = True
ElseIf dr("strStockGroup") = "Video" Then
rdbVideo.Checked = True
ElseIf dr("strStockGroup") = "Computer Game"
Then
rdbComputerGame.Checked = True
End If

This works as long as I have "Option Strict" set
to "Off". Otherwise i get the error "Option strict on
disallows operands of type object for operator '='.
Use the 'Is' operator to test for object Identity"

Unfortunately I am required to have "Option Strict" set
to "ON". Any ideas on how I can make this work?

Greg

If you know that the field type is String:

Select case dr("strStockGroup").ToString
case "DVD"
case "Video"
case "Computer Game"
end select


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top