在'If'语句vb .net中调用函数 [英] Call a function in an 'If' statement vb .net
问题描述
我想在'If'语句中调用一个函数,我之前已经完成了这个,但它有所不同。我之前就是这样做的:
I want to call a function in an 'If' statement, I have done this before but it was different. This is how I did it before:
If Not validatePhone(txtContactNumber.Text) Then
......
End If
这对我来说很简单,因为我知道要放在括号中的内容,但我想调用一个检查数据库的函数:
That is straight forward for me because I know what to put in the brackets, but I want to call a function that checks that a database:
If Not checkDatabaseExists() Then
......
End If
我不知道这里的括号中有哪些参数。这是函数'checkDatabaseExists'的代码:
I do not know what parameters go into the brackets here. This is the code for the function 'checkDatabaseExists':
Public Shared Function checkDatabaseExists(ByVal server As String, ByVal database As String) As Boolean
Dim conString As String = ("Data Source=.\SQLExpress;Initial Catalog=Visitors;Integrated Security=True;MultipleActiveResultSets=True")
Dim cmdText As String = ("SELECT * FROM master.dbo.sysdatabases WHERE Name=Visitors")
Dim databaseExists As Boolean = False
Using sqlConnection As SqlConnection = New SqlConnection(conString)
sqlConnection.Open()
Using sqlCmd As SqlCommand = New SqlCommand(cmdText, sqlConnection)
Using reader As SqlDataReader = sqlCmd.ExecuteReader
databaseExists = reader.HasRows
End Using
End Using
End Using
Return databaseExists
End Function
有人能帮帮我吗?我知道这很简单,当我发现它是什么时我会自己踢,但不幸的是,我现在还没有线索。非常感谢所有这方面的帮助。
编辑:
我收到以下错误在'If'语句的checkDatabaseExists()部分中有参数:
'未在公共共享函数checkDatabaseExists的参数database中指定参数(ByVal服务器为String,ByVal database As String)As Boolean'
Can anyone help me? I know it's something simple and I'll be kicking myself when I find out what it is but I haven't a clue at the moment unfortunately. All help with this matter would be greatly appreciated.
I get the following error without having parameters in the checkDatabaseExists() part of the 'If' statement:
'Argument not specified for parameter "database" of "Public Shared Function checkDatabaseExists(ByVal server As String, ByVal database As String) As Boolean" '
推荐答案
仅回答从未答复的队列中删除。
Answered only to remove from the unanswered queue.
这篇关于在'If'语句vb .net中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!