当前位置: 动力学知识库 > 问答 > 编程问答 >

VB.NET: How to check input if it is existing in the Dataset before adding

问题描述:

I need to check the user input before it is inserted in the dataset.

here is my code.

 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

The problem with this code is even though I input different number in txtaccn.text, foundRows

网友答案:

I guess the problem is with the line

If foundRows Is Nothing Then

Maybe trying this might help,

If foundRows.Length = 0 Then
'Add to DataTable
分享给朋友:
您可能感兴趣的文章:
随机阅读: