如何将csv文件中的数据字符串匹配到Visual Basic上的输入?

时间:2018-07-27 05:33:56

标签: visual-studio visual-studio-2010

Private Sub txtName_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.LostFocus
        Try
            Dim filereader As New IO.StreamReader("C:\Users\hanna\Desktop\SCHOOL 2018 (MAY)\VB Assignment\VB Assignment\My Project\StudentDetails.csv")
            While filereader.EndOfStream = False
                Details = filereader.ReadLine.Split(",")

                If txtName.Text.ToUpper() = Details(0).ToUpper() Then
                    Match = True

                End If

            End While
        Catch
            Match = True
            MessageBox.Show("Student has already been added to the system", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
        Match = False
    End Sub

尽管可以工作,但我在表单上键入的任何内容都会出现在消息框中。我的意图是仅在单击表单上的“保存”按钮后显示消息框。我希望您能指出问题所在。

0 个答案:

没有答案