i want to compare between the cell value with the value(parameter) in database.

as example, if my cellvalue value is 3 and my paramater(a) in my database is 5 it will be like this
if cellvalue<a then
(some code)
end if

the problem is i don't know the exact data type. the reason i need to use data type is because my data is dynamic.

here is my code:

protected SubGridView1_RowDataBound(ByVal Sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Users\me\Documents\Visual Studio 2005\WebSites\CSG\CSG1.mdb") 
detReport = New OleDbDataAdapter("Select * From parameterData WHERE (alert_ID = 'CR') AND (alert_type = alert_ID)", con) 
Dim a As Int32 
if e.Row.RowType = DataControlRowType.DataRow Then
Dim CellValue As Decimal = convert.ToDecimal(e.Row.cells(4).text) 
if CellValue < a then 
e.Row.Cells(4).BackColor = Drawing.Color.Red 
End if 
End if 
End Sub

i hope that you all can help me. thanks in advance :)

6 Years
Discussion Span
Last Post by Oxiegen

In order to determine the datatype, you first need to determine the content type.
If the content type is String, then you need to find out if it's strictly numeric.
And if that is the case, then the content can be cast as Integer/Double/Decimal, or else you have to do something else with the information.

When that is done, you can perform your comparison.

Dim cellData As String = e.Row.Cells(4).Text
For Each c As Char In cellData
   If Not Char.IsNumeric(c) Then
      'The cell contains text, so do something about it

      'Jump out of the method, because you can't compare text ("abc") with numbers (123)
      Exit Sub
   End If

'Then continue with your coding
Dim CellValue As Decimal = Convert.ToDecimal(cellData)
If CellValue < CDec(a) Then
   e.Rows.Cells(4).BackColor = Drawing.Color.Red
End If

Edited by Oxiegen: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.