Click here to Skip to main content
15,791,496 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone. I want to execute an Else If condition by checking the data in Table field in sql. for example.

If the value of TableField =1 Then
(condition here)
End if

I dont really know how to code that one. I been searching in the google similar to my problem but I didn't find it.

please help me. thanks.

What I have tried:

If Val(Select DataField from Tablename) =1 Then

Me. Hide()

End if
Updated 26-Dec-16 2:42am
ZurdoDev 16-Dec-16 11:24am    
Is this VBA or VB?

Look for ADO.Net examples. You'll want to use SqlConnection and SqlCommand objects.
Member 12905345 16-Dec-16 20:49pm    
I am using a vb. net

1 solution

Dim myConn As SqlConnection
     Dim myCmd As SqlCommand
     Dim myReader As SqlDataReader
     Dim results As String

     myConn = New SqlConnection("Initial Catalog=MyDataBase;Data Source=SQLServerName\SqlServerInstance;Uid=MyUser;Pwd=Pass123;")

     myCmd = myConn.CreateCommand
     myCmd.CommandText = "Select DataField from Tablename"

     'Open the connection.
     myReader = myCmd.ExecuteReader()
     If myReader.GetValue(0) = 1 Then
        Me. Hide()
     End If
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900