搜索选项:位置3没有行 [英] Search option : There is no row at position 3

查看:86
本文介绍了搜索选项:位置3没有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过搜索来显示数据库中文本框中的记录..我为输出显示提供了6个文本框,但我在搜索时遇到错误在第3位没有行,如果没有记录在位置3,然后它应该在下面的文本框中显示零值。

请找到下面的代码并帮助我



I want to display records in Textboxs from the database, by searching.. I given 6 Textboxs for the output display, but I'm getting an error while searching" There is no row at position 3", If there is no records in position 3, then it should display Zero value in that following textbox.
Please find the below code and help me

Dim con As New OleDb.OleDbConnection
       con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\dbexport.accdb;Persist Security Info=False;"
       con.Open()
       Dim dt As New DataTable


       Dim rs As New OleDb.OleDbDataAdapter("Select * from QA_db where eNB_Name Like '%" & search_box.Text & "%' ", con)
       rs.Fill(dt)


       '/// Display Search data feilds in textbox //

      EUtran1_txt.Text = dt.Rows(0).Item("EUtranCellFDD_Name")
      EUtran2_txt.Text = dt.Rows(1).Item("EUtranCellFDD_Name")
      EUtran3_txt.Text = dt.Rows(2).Item("EUtranCellFDD_Name")
      EUtran4_txt.Text = dt.Rows(3).Item("EUtranCellFDD_Name")
      EUtran5_txt.Text = dt.Rows(4).Item("EUtranCellFDD_Name")
      EUtran6_txt.Text = dt.Rows(5).Item("EUtranCellFDD_Name")

       rs.Dispose()

       con.Close()

推荐答案

请检查Rows.Count属性...

So check the Rows.Count property...
If DT.Rows.Count >0 Then
   EUtran1_txt.Text = dt.Rows(0).Item("EUtranCellFDD_Name")
End If
...

为每一行重复一次,并带有相应的计数和行号。

repeat for each row, with the appropriate count and row number.


您也可以尝试以下方法:



You can also try something like:

For row as Integer = 0 to dt.Rows.Count - 1
   GetTextBoxForRow(row).text = dt.Rows(row).Item("EUtranCellFDD_Name")
Next

Function GetTextBoxForRow(ByVal rowNumber as Integer) as TextBox
     Select Case rowNumber

        Case 0 : return EUtran1_txt
        Case 1 : return EUtran2_txt
        Case 2 : return EUtran3_txt
        Case 3 : return EUtran4_txt
        Case 4 : return EUtran5_txt
        Case 5 : return EUtran6_txt

     End Select
End Function





In这个解决方案循环将运行唯一可用的行数。



In this solution the loop will run for the only available number of rows.


这篇关于搜索选项:位置3没有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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