Question problem with datatype

nutsxiera

Member
Joined
Aug 5, 2010
Messages
7
Programming Experience
1-3
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:

VB.NET:
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") 

con.Open() 
detReport = New OleDbDataAdapter("Select * From parameterData WHERE (alert_ID = 'CR') AND (alert_type = alert_ID)", con) 

Dim a As Int32 
DetReport.Equals(a) 

 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  

con.close()
  
End Sub

hope that you all can help me :)
thanks in advance
 
If you're comparing using < then presumably your values are all numbers. In that case, simply convert everything to Decimal and compare as Decimal. Any numeric type can be converted to Decimal so it won;t matter what the original data type was.
 
thanks for the reply :)

i change all to decimal, but still the result carry the old parameter.
the problem is i dont know how to connect the value from the database that carry the parameter in table parameter with the value on cell that is been call from different table.

the only reason i use the database value as my parameter is because my system allow user to change the parameter value. so that the cell must be compare with the parameter value that the user key in.
 
I think you should consider restricting the value that is entered into the cell prior to anything else happening, to ensure that the value entered can be converted into a type you expect. In this case an integer value, since that is the parameter's type. You can use the Int32.TryParse() method to validate the value entered, and put the focus back to that cell if the tryparse fails.
 
Back
Top