Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2006-09-15 : 11:27:10
|
I have a datagrid, and am having trouble when the value is NULL. When I run the page I get:Operator is not valid for type 'DBNull' and string "F". When the code hit's a value of NULL in the database, the error occurs. If the value in the table is "F", then I get "Funded"...which is correct.I've tried several things to handle the NULL value, but can't get around the error.Here's the HTML:<asp:Templatecolumn HeaderText="Status"> <ItemTemplate> <%# DisplayStatus(DataBinder.Eval(Container.DataItem, "WkPkgStatus"))%> </ItemTemplate></asp:Templatecolumn>Here's the code behind: Function DisplayStatus(ByVal WkPkgStatus As Object) As String Select Case WkPkgStatus Case "F" Return "Funded" Case "U" Return "UnFunded" Case "R" Return "RollUp" Case IsDBNull(WkPkgStatus.Value) Return "Not Set" Case Else Return "Not Set" End SelectEnd FunctionThanks! |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-09-15 : 11:48:11
|
Function DisplayStatus(ByVal WkPkgStatus As Object) As StringIf WkPkgStatus = "F" ThenReturn "Funded"ElseIf WkPkgStatus = "U" ThenReturn "UnFunded"ElseIf WkPkgStatus = "R" ThenReturn "RollUp"ElseIf IsDBNull(WkPkgStatus.Value) ThenReturn "Not Set"ElseReturn "Not Set"End IfEnd FunctionPeter LarssonHelsingborg, Sweden |
 |
|
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2006-09-15 : 15:54:55
|
Peso, thanks for the reply.I used this, and it worked:Function DisplayStatus(ByVal WkPkgStatus As Object) As String If Not IsDBNull(WkPkgStatus) Then Select Case WkPkgStatus Case "F" Return "Funded" Case "U" Return "UnFunded" Case "R" Return "RollUp" Case Else Return "Not Set" End Select Else Return "Not Set" End IfEnd Function |
 |
|
|
|
|