我得到一个消息框为“在0位没有行”。 [英] Am getting a message box as "There is no row at position 0."

查看:78
本文介绍了我得到一个消息框为“在0位没有行”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击搜索按钮没有任何输入时,我得到一个消息框为位置0没有行。然后当我点击确定然后我的消息为请输入要搜索的ID



When i click the Search button with out any input ,Am getting a message box as "There is no row at position 0." and then when i click on Ok then am getting my message as "Please enter an ID to search"

Private Sub BtnSearch_Click(sender As Object, e As EventArgs) Handles BtnSearch.Click
       Try
           FillDataGridView1("select * from [Sheet1$] where ID='" & TxtId.Text & "'")
           TxtFamilyname.Text = dt.Rows(0).Item(1)
           TxtGivenname.Text = dt.Rows(0).Item(2)
           TxtGender.Text = dt.Rows(0).Item(3)
           TxtDob.Text = dt.Rows(0).Item(4)
           TxtStreet.Text = dt.Rows(0).Item(5)
           TxtHouse.Text = dt.Rows(0).Item(6)
           TxtPostcode.Text = dt.Rows(0).Item(7)
           TxtCity.Text = dt.Rows(0).Item(8)
       Catch ex As Exception
           MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
       End Try

       If TxtId.Text = "" Then
           MsgBox("Please enter a ID to search")
       End If

   End Sub

推荐答案

其中ID ='& TxtId.Text& ')
TxtFamilyname.Text = dt.Rows(0).Item(1)
TxtGivenname.Text = dt.Rows(0).Item(2)
TxtGender.Text = dt.Rows(0).Item(3)
TxtDob.Text = dt.Rows(0).Item(4)
TxtStreet.Text = dt.Rows(0).Item(5)
TxtHouse.Text = dt.Rows(0).Item(6)
TxtPostcode.Text = dt.Rows(0).Item(7)
TxtCity.Text = dt.Rows(0 ).Item(8)
Catch ex As Exception
MsgBox(ex.Message,MsgBoxStyle.Critical,Text)
结束尝试

如果TxtId.Text = 那么
MsgBox(请输入要搜索的ID)
结束如果

结束次级
where ID='" & TxtId.Text & "'") TxtFamilyname.Text = dt.Rows(0).Item(1) TxtGivenname.Text = dt.Rows(0).Item(2) TxtGender.Text = dt.Rows(0).Item(3) TxtDob.Text = dt.Rows(0).Item(4) TxtStreet.Text = dt.Rows(0).Item(5) TxtHouse.Text = dt.Rows(0).Item(6) TxtPostcode.Text = dt.Rows(0).Item(7) TxtCity.Text = dt.Rows(0).Item(8) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, Text) End Try If TxtId.Text = "" Then MsgBox("Please enter a ID to search") End If End Sub


因为您在检查输入之前正在进行搜索。尝试稍微改变一下



Because you are doing the search before checking the input. Try changing things around a bit

Private Sub BtnSearch_Click(sender As Object, e As EventArgs) Handles BtnSearch.Click

        If TxtId.Text = "" Then
            MsgBox("Please enter a ID to search")
            Exit Sub
        End If

        Try
            FillDataGridView1("select * from [Sheet1


where ID ='& TxtId.Text&')
TxtFamilyname.Text = dt.Rows(0)。 Item(1)
TxtGivenname.Text = dt.Rows(0).Item(2)
TxtGender.Text = dt.Rows(0).Item(3)
TxtDob.Text = dt.Rows(0).Item(4)
TxtStreet.Text = dt.Rows(0).Item(5)
TxtHouse.Text = dt.Rows(0).Item(6)
TxtPostcode.Text = dt.Rows(0).Item(7)
TxtCity.Text = dt.Rows(0).Item(8)
Catch ex As Exception
MsgBox (ex.Message,MsgBoxStyle.Critical,Text)
结束尝试


End Sub
where ID='" & TxtId.Text & "'") TxtFamilyname.Text = dt.Rows(0).Item(1) TxtGivenname.Text = dt.Rows(0).Item(2) TxtGender.Text = dt.Rows(0).Item(3) TxtDob.Text = dt.Rows(0).Item(4) TxtStreet.Text = dt.Rows(0).Item(5) TxtHouse.Text = dt.Rows(0).Item(6) TxtPostcode.Text = dt.Rows(0).Item(7) TxtCity.Text = dt.Rows(0).Item(8) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, Text) End Try End Sub


这篇关于我得到一个消息框为“在0位没有行”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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