检查字段值以执行条件 [英] Checking the field value to execute conditions

查看:71
本文介绍了检查字段值以执行条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我想通过检查sql中Table字段中的数据来执行Else If条件。例如。



如果TableField的值= 1那么

(条件在这里)

结束如果



我真的不知道如何编码那个。我一直在谷歌搜索类似于我的问题,但我没有找到它。



请帮帮我。谢谢。



我尝试了什么:



如果是Val(选择来自Tablename的DataField = 1然后



我。隐藏()

Form2.Show()



如果

解决方案

  Dim  myConn  As  SqlConnection 
Dim myCmd As SqlCommand
Dim myReader As SqlDataReader
Dim 结果 As 字符串

myConn = SqlConnection( 初始目录= MyDataBase;数据源= SQLServerName \SqlServerInstance; Uid = MyUser; Pwd = Pass123;

myCmd = myConn.CreateCommand
myCmd.CommandText = 从Tablename中选择DataField

' 打开连接。
myConn.Open()
myReader = myCmd。 ExecuteReader()
myReader.Read()
如果 myReader.GetValue( 0 )= 1 然后
。隐藏()
Form2.Show()
结束 如果


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

解决方案

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


这篇关于检查字段值以执行条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆