我是vb的新手,我正在创建一个项目,我可以编辑帐户到目前为止我遇到了问题。当我的数据库中的值为NULL
时,.read
函数停止
ElseIf ButtonChoice = 2 Then
txtIDnumber.Text = val
Dim EditFamilyProfile As New SqlCommand("Select * From [186].[dbo].[familyInfo] WHERE pFnumber = @pFnumber", Connection)
EditFamilyProfile.CommandType = CommandType.Text
EditFamilyProfile.Parameters.AddWithValue("@pFnumber", txtIDnumber.Text)
Dim drEdit As SqlDataReader
drEdit = EditFamilyProfile.ExecuteReader
With drEdit
.Read()
txtLastName.Text = .Item(1)
txtFirstName.Text = .Item(2)
txtMiddleName.Text = .Item(3)
txtExt.Text = .Item(4)
txtAddress.Text = .Item(5)
cmbGender.Text = .Item(6)
.close()
End With
End If
它在txteExt.text
中停止,因为它具有NULL值。没有显示错误。它只是去代码:
ButtonChoice = 2
Dim obb As New frm_FamilyReg
obb.val = Me.txtIDnumber.Text()
obb.Show()
Me.Close()
答案 0 :(得分:0)
使用IsDBNull()
函数检查您是否有dbNUll值,如果有,请跳过它。
if not IsDBNull(txtLastName.Text = .Item(1)) then
txtLastName.Text = .Item(1)
End If