从字符串“firstnametextbox.text”转换错误描述像''输入整数是无效的,以便从网格中搜索 [英] Error description conversion from string "firstnametextbox.text" like' ' to type integer is not valid in order to search from the grid

查看:91
本文介绍了从字符串“firstnametextbox.text”转换错误描述像''输入整数是无效的,以便从网格中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        On Error GoTo SearchErr
        If txtsearch.Text = " " Then
            Call notfound()
            Exit Sub

        Else
            Dim cantfind As String = txtsearch.Text
            Me.dgvfill()

            DoctorBindingSource.Filter = ("Doctor_s_NHS_NoTextBox.Text  like  '" & txtsearch.Text & "'")("FirstnameTextBox.Text like '" & txtsearch.Text & "'") & _
               ("SurnameTextBox.Text like '" & txtsearch.Text & "'")("Medical_Center_NameTextBox.Text like '" & txtsearch.Text & "'") & _
                ("Email_AddressTextBox.Text like '" & txtsearch.Text & "'")("Patient_NHS_NumberTextBox.Text like '" & txtsearch.Text & "'") & _
                ("GP_Appointment_RefTextBox.Text like '" & txtsearch.Text & "'")("Patient_IDTextBox.Text like '" & txtsearch.Text & "'")

            If DoctorBindingSource.Count <> 0 Then
                With DoctorDataGridView
                    .DataSource = DoctorBindingSource
                End With
            Else
                Me.notfound()
                MsgBox("--> " & cantfind & vbNewLine & _
                       "The search item was not found", _
                       MsgBoxStyle.Information, "Hey Boss")
                DoctorBindingSource.Filter = Nothing

                With DoctorDataGridView
                    .ClearSelection()
                    .ReadOnly = True
                    .MultiSelect = False
                    .DataSource = DoctorBindingSource
                End With

            End If

        End If

ErrExit:
        Exit Sub
SearchErr:
        MsgBox("error number" & Err.Number & vbNewLine & _
               "error description " & Err.Description, MsgBoxStyle.Critical, _
               "reset error!")
        Resume ErrExit

    End Sub

    Private Sub reset()
        Dim txtS As TextBox = txtsearch
        With txtS
            .Text = ""
            .Select()
            .BackColor = Color.LightCyan
        End With
        cboOfColor.SelectedItem = "MistyRose"
        cboAltColor.SelectedItem = "Gold"

        cboOfColor.BackColor = Color.LightCyan
        cboAltColor.BackColor = Color.LightCyan
        If DoctorDataGridView.DataSource Is Nothing Then
            Exit Sub
        End If
        Dim dgv As DataGridView = DoctorDataGridView
        With dgv
            .RowsDefaultCellStyle.BackColor = Color.FromName(cboOfColor.SelectedItem)
            .AlternatingRowsDefaultCellStyle.BackColor = Color.FromName(cboAltColor.SelectedItem)
        End With

    End Sub
    Private Sub dgvfill()
        txtsearch.BackColor = Color.LightBlue
        If DoctorDataGridView.DataSource Is Nothing Then
            Exit Sub
        End If
        Dim dgv1 As DataGridView = DoctorDataGridView
        With dgv1
            .RowsDefaultCellStyle.BackColor = Color.FromName(cboOfColor.SelectedItem)
            .AlternatingRowsDefaultCellStyle.BackColor = Color.FromName(cboAltColor.SelectedItem)
        End With

    End Sub
    Private Sub notfound()
        Dim txtS As TextBox = txtsearch
        With txtS
            .BackColor = Color.White
            .Select()
            .SelectAll()

        End With
        If DoctorDataGridView.DataSource Is Nothing Then
            Exit Sub
        End If
        Dim dgv2 As DataGridView = DoctorDataGridView
        With dgv2
            .RowsDefaultCellStyle.BackColor = Color.White
            .AlternatingRowsDefaultCellStyle.BackColor = Color.White
        End With



    End Sub

End Class





我尝试了什么:



i尝试将这些字段初始化为整数,但仍然是发生错误...因为我认为在文本框的开头有使它成为字符串... plz帮助我



What I have tried:

i try to initialize these fields as integer but still the error occurs ...because i think there is " " in the starting of the textbox which make it string...plz help me out

推荐答案

在过滤器中你需要指定列并与值进行比较。例如

In the filter you need to specify the column and comparison to a value. For example
"Name LIKE '" & txtsearch.Text & "*'"



您无法在查询中嵌入文本框,就像您尝试过的那样。



所以用列名替换文本框名称,并将过滤器的值连接到符号中。



此外,由于您有多个条件,您需要在它们之间使用AND或OR。



有关更多信息,请查看 BindingSource.Filter属性(System.Windows.Forms) [ ^ ]和 DataColumn .Expression属性(System.Data) [ ^ ]


这篇关于从字符串“firstnametextbox.text”转换错误描述像''输入整数是无效的,以便从网格中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆