在那里,我正在对我的全面运作的SMS应用程序进行单元测试。
我有一个包含这些代码的模块
Public Class frmDatabaseConnection
'If Statement for Database Connection
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Try
If sqlconnect(txtServer.Text, txtUsername.Text, txtPassword.Text) = True Then
Dim query(8) As String
query(0) = "Create database if not exists dbsms;"
query(1) = "Use dbsms;"
query(2) = "Create table if not exists tbl_administrator(SecretCode varchar(10) not null default '', Username varchar(20), Password varchar(20),Primary Key(SecretCode));"
query(3) = "Create table if not exists tbl_students(Idno varchar(10) not null default'',Name varchar(60), Course varchar(10), YearSec varchar(20), Organization varchar(20), MobileNum varchar(15), Primary Key(Idno));"
query(4) = "Create table if not exists tbl_user(Username varchar(20) not null default '', Password varchar(20), Name varchar(20), Position varchar(20), MobileNum varchar(15), Primary key(Username));"
query(5) = "Create table if not exists tbl_announcement(ID int(10) not null auto_increment, Recipients varchar(40), Description varchar(500), CDate varchar(100), Sender varchar(30), AnnouncementStatus varchar(20), Primary key(ID));"
query(6) = "Create table if not exists tbl_activity(ID int(10) not null auto_increment, Username varchar(20), Activity varchar(30),CDate varchar(50), Primary key(ID));"
query(7) = "Create table if not exists tblgetname(ID int(10) not null auto_increment, UserName varchar(20), Primary key(ID));"
query(8) = "Create table if not exists tbl_inbox(ID int(10) not null auto_increment, message varchar(300), received_date varchar(50), sender varchar(30), Primary key(ID));"
'For statement for database and tables
For i As Integer = 0 To 8
'If statement for executing all query
If command(query(i).ToString) Then
'If statement for Assuring all query are executed
If i >= 8 Then
MessageBox.Show("Database Connected", "Database Connection", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
'End of If statement for Assuring all query are executed
Else
MessageBox.Show(fail)
End If
'End of If statement for executing all query
Next
'End of For statement for database and tables
'Function which contains Sql Command for Selecting Administrators SecretCode
SelectSecretCode()
'If Statement for assuring SecretCode contains value
If myr.HasRows Then
'If SecretCode contains value Log In form will be shown
Login.Show()
Me.Hide()
Else
'If SecretCode contains no value Create Admin form will be shown to create Admin Account
CreateAdmin.Show()
Me.Hide()
End If
'End of If Statement for assuring SecretCode contains value
Else
MessageBox.Show(fail, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
clear()
End If
'End of If Statement for database connection
myr.Close()
Catch ex As Exception
MsgBox("Invalid use of special characters and symbols")
End Try
End Sub
Public Sub clear()
txtServer.Clear()
txtUsername.Clear()
txtPassword.Clear()
End Sub
Public Sub SelectSecretCode()
mycom.Connection = cn
mycom.CommandText = "Select SecretCode from tbl_administrator"
myr = mycom.ExecuteReader
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
If MessageBox.Show("Exit System", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
Me.Close()
Application.Exit()
End If
End Sub
Private Sub frmDatabaseConnection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
带有这些值的数据库连接窗口
Public Sub SelectSecretCode()
mycom.Connection = cn
mycom.CommandText = "Select SecretCode from tbl_administrator"
myr = mycom.ExecuteReader <-------error
End Sub
当我运行我的系统时,所有这些代码都非常流畅。我可以建立与数据库的连接。我可以比这个表单更进一步保存和检索进程数据。 但是当我开始在我的系统中执行单元测试时,我发现了一个错误,如下图所示。
它继续出现在这行代码上
{{1}}
我还添加了第二张图片以获取更多信息
任何解决方案或帮助都非常贴切,因为我们已经没时间了。感谢