Click here to Skip to main content
15,912,756 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()
Form2.Show()

End if
Posted
Updated 26-Dec-16 1:42am
Comments
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

VB
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.
     myConn.Open()
     myReader = myCmd.ExecuteReader()
     myReader.Read()
     If myReader.GetValue(0) = 1 Then
        Me. Hide()
        Form2.Show()
     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