Question compare string to database column

clzanas

Member
Joined
Jul 15, 2009
Messages
16
Programming Experience
Beginner
Hi guys,

I am having trouble comparing a input string to a table column from the sql database. As my program logic is. if the string handphone number = to the data in the database column, then it will execute the alarm, else it will not.

So i have put something like

VB.NET:
If pnum = dsColumn("handphoneNumber") Then
                    MsgBox("Fire Alert")

                    MySoundPlayer.SoundLocation = _
                                   "E:\My documents\TP\sem 6 MPSIP\more to project\mpsip things needed\work from here!!\AUTO INCOMING SMS\Sound Effect - Police Siren 02.wav"
                    MySoundPlayer.Load()
                    MySoundPlayer.Play()
                    ' read.Close()
                    ' conn1.Close()
                    myCommand1.Parameters.Clear()

                End If

the code, If pnum = dsColumn("handphoneNumber") Then, will do the comparasion.

Cause now i'm using this method to compare but i'm getting the error something like dbnull.

regards,

clzanas
 
Hi,

I want to know what dsColumn is. Please show its declaration also.

Another question is whether you are comparing with the column name or with the data in the column and if it is that you are not specifying the particular row.

Thanks
Panna
 
My guess is that dsColumn is actually a DataRow and the column in the row to look at is "handphoneNumber"

Anyways to compare a String from a DB column like that you need to convert it from Object to String and the Convert.ToString() method is nice because it returns a String.Empty if the column is DBNull.Value:
VB.NET:
If pnum = Convert.ToString(dsColumn("handphoneNumber")) Then

End If
 

Latest posts

Back
Top