ASP.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a ASP.NET Expert!

Join 307,013 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 2,052 people online right now. Registration is fast and FREE... Join Now!




compare null values

 

compare null values

gagansharma91

25 Jun, 2009 - 10:38 PM
Post #1

New D.I.C Head
*

Joined: 30 Apr, 2009
Posts: 19


My Contributions
suppose strSql1 contains null value , then how i compare it with a null value in if statement, pls help me

CODE

StrSql1 = "SELECT CAST(MAX(GRV_CODE) AS INTEGER)+1 AS CNT FROM GRIEVANCE_DETAILS WHERE EST_CODE='" & DRP_DEPT.SelectedValue & "' "
        sqlcmd = New SqlCommand(StrSql1, dbcon)
        dbcon.Open()
        SqlRs = sqlcmd.ExecuteReader
        'If IsDBNull(StrSql1("cnt")) Then
        If IsDBNull(StrSql1(0)) Then
            'If IsDBNull(StrSql1) Then
            nextcode = CType(1, String)
        Else
            While SqlRs.Read()
                nextcode = Right("00" & CStr(SqlRs("cnt")), 2)
            End While
        End If


User is offlineProfile CardPM
+Quote Post


baavgai

RE: Compare Null Values

26 Jun, 2009 - 03:41 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,348



Thanked: 411 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
This is more a VB problem than ASP.NET. I'm not ever sure this is VB.NET, some of it looks like VBScript. I loathe VB syntax, so code my be slightly off...

You're problem is that you don't know what you've got until you try to get it, e.g, SqlRs.Read(). Also, you will only get a single value. The While is overkill.

vb

nextcode = "00" ' default value
StrSql1 = "SELECT CAST(MAX(GRV_CODE) AS INTEGER)+1 AS CNT FROM GRIEVANCE_DETAILS WHERE EST_CODE='" & DRP_DEPT.SelectedValue & "' "
sqlcmd = New SqlCommand(StrSql1, dbcon)
dbcon.Open()
SqlRs = sqlcmd.ExecuteReader
' we have two options here, 0 or 1 results
If SqlRs.Read() Then
' assuming this actually is a DbDataReader http://msdn.microsoft.com/en-us/library/sy...er_members.aspx
' we've got 1 result
' is it null
If SqlRs.IsDBNull(0) Then
nextcode = Right("00" & SqlRs(0).ToString()), 2)
End If
End If
dbcon.Close()



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:24AM

Live ASP.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

ASP.NET Tutorials

Reference Sheets

ASP.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month