我需要在用户输入插入数据集之前检查它。 这是我的代码。
If ds.Tables(0).Rows.Count > 0 Then
foundRows = ds.Tables(0).Select("AccessionNumber = '" + txtaccn.Text + "'")
End If
If book.checkifaccnexist(txtaccn.Text) = 1 Then
If foundRows Is Nothing Then
dt.Rows.Add(New Object() {txtaccn.Text})
acn = acn.Insert(acn.Length, (" OR accn = '" + Label1.Text + "'"))
txtaccn.Clear()
Else
MetroFramework.MetroMessageBox.Show(Me, "The accession number you've inputed is already in the list", "Library Management System", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtaccn.Clear()
End If
Else
MetroFramework.MetroMessageBox.Show(Me, "Accession Number Doesn't exist", "Library Management System", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtaccn.Clear()
End If
此代码的问题是即使我在txtaccn.text中输入了不同的数字, foundRows
答案 0 :(得分:1)
我猜问题就在于行
If foundRows Is Nothing Then
也许尝试这可能会有所帮助,
If foundRows.Length = 0 Then
'Add to DataTable