添加函数:
- '写一个添加用户信息的方法,它的返回值是布尔型, Function AddUser(ByVal User As DBuser) As Boolean '首先判断用户名是否已经存在 Dim SQLString As String SQLString = "SELECT * FROM telephonebook WHERE 姓名 ='" & nm & "" Dim oneTable As DataTable = DBOperation.DBOperate(SQLString) If oneTable.Rows.Count >= 1 Then MsgBox("输入的联系人已经存在,请重新输入", MsgBoxStyle.Exclamation, "消息框") Return False Else SQLString = "INSERT INTO telephonebook VALUES('" & nm & "','" & no1 & "','" & no2 & "','" & nohm & "','" & addr & "','" & qq & "','" & email & "')" DBOperation.DBOperate(SQLString) MsgBox("成功添加联系人信息", MsgBoxStyle.Exclamation, "消息框") Return True End If End Function 添加函数的调用
-
'这里我们采用的是实例化DBUser,产生一个实例化对象,做为我们后面要传进去的参数
Dim tempTable As New DBuser(Trim(Me.nm.Text))
' 将我们在界面输入的信息填充到我们临时的表中
tempTable.nm = Trim(Me.nm.Text)
tempTable.no1 = Trim(Me.no1.Text)
tempTable.no2 = Trim(Me.no2.Text)
tempTable.nohm = Trim(Me.nohm.Text)
tempTable.addr = Trim(Me.addr.Text)
tempTable.qq = Trim(Me.qq.Text)tempTable.email = Trim(Me.email.Text) '这样tempTable中的信息就完善啦!下一步进行实例传入 User.AddUser(tempTable)
调试添加功能时User.AddUser(tempTable)这一行显示:未处理NullReferenceException 未将对象引用设置到对象的实例 "
删除函数调用时也是调试卡在了相同的地方。