-1

My problem now is about how to use "not equal" in SQL. Here is my code:

Dim cmd As New SqlClient.SqlCommand
    With cmd
        .CommandText = "SELECT [Position],[Partylist],[Fullname],[Lvl],[Votes] FROM tbl_cands WHERE [Department] = '" & elem & "'AND [PositionID]=" & pres & ""
        .CommandType = CommandType.Text
        .CommandTimeout = 30
        .Connection = conn
    End With
    Dim dt As New DataTable
    dt.Load(cmd.ExecuteReader)

I need not to display fullname that is not equivalent to None.

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

1

All you have to do is to add that to your query:

AND [Fullname] <> 'None'
Szymon
  • 42,577
  • 16
  • 96
  • 114
1

If you are checking for NULL then the code is:

AND [Fullname] IS NOT NULL

If you want to check the value isn't a zero length string:

AND [Fullname] <> ''

If you want to check it isn't a specific value that denotes no data:

AND [Fullname] <> 'None'

But in any case, I strongly recommend you read the following link and learn how to use parameterization for your SqlCommand object. If you don't escape strings correctly you leave yourself vulnerable to injection hacks:

How to use parameters "@" in an SQL command in VB

Community
  • 1
  • 1
Polynomial
  • 3,656
  • 23
  • 36