如何解决索引超出范围的异常 [英] how to fix index out of range exception

查看:636
本文介绍了如何解决索引超出范围的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 功能 DispalyGuardianDetials( ByVal 用户名字符串 As  整数) As  整数
        Dim  Sqlcust  As   String 
        Dim 电话号码 As  字符串
        Dim  spt() As  字符串
        Dim  i  As   Int16 
       Sqlcust = " 
       如果 Stype =  0  >然后
           Sqlcust = " &用户名和用户名" 
        ElseIf  Stype =  1  然后
           Sqlcust = " &用户名和用户名" 
       结束 如果
       ' 调用clearfieldsGaurdian()
       Rsc = 新建 SqlCommand(Sqlcust,骗局)
       '  Rsc.ExecuteNonQuery()
       Rsd = Rsc.ExecuteReader()
       如果 Rsd.Read = 真实 然后

           TxtGname.Text = Rsd(" )
           TxtGucode.Text = Rsd(" )
                               错误 索引了 范围例外用户代码未处理
           TxtGAge.Text = Rsd(" )
           TxtGDob.Text = Rsd(" )
           TxtGRelationship.Text = Rsd(" )
           TxtGAdd.Text = Rsd(" )
           TxtGLand.Text = Rsd(" )
           TxtGPin.Text = Rsd(" )
           TxtGArea.Text = Rsd(" )
           TxtGCity.Text = Rsd(" )
           TxtGState.Text = Rsd(" )
           TxtGCountry.Text = Rsd(" )

解决方案

验证您在 Tbl_MstGuardian 表中是否具有 usercode 列.

可能是列不存在或列名中的拼写错误. ,在每个语句中逐步执行代码,并在断点处停止执行时使用监视"窗口验证值.


Function DispalyGuardianDetials(ByVal UserName As String, ByVal Stype As Integer) As Integer
       Dim Sqlcust As String
       Dim Phonenumber As String
       Dim spt() As String
       Dim i As Int16
       Sqlcust = ""
       If Stype = 0 Then
           Sqlcust = "select*from Tbl_MstGuardian where CONTACTNAME='" & UserName & "'"
       ElseIf Stype = 1 Then
           Sqlcust = "select*from Tbl_MstGuardian where Maxid='" & UserName & "'"
       End If
       'Call clearfieldsGaurdian()
       Rsc = New SqlCommand(Sqlcust, con)
       'Rsc.ExecuteNonQuery()
       Rsd = Rsc.ExecuteReader()
       If Rsd.Read = True Then

           TxtGname.Text = Rsd("contactname")
           TxtGucode.Text = Rsd("usercode")
                               The error is Index out of range exception was unhandled by usercode            
           TxtGAge.Text = Rsd("AGE")
           TxtGDob.Text = Rsd("DOB")
           TxtGRelationship.Text = Rsd("relationship")
           TxtGAdd.Text = Rsd("ADDRESS1")
           TxtGLand.Text = Rsd("landmark")
           TxtGPin.Text = Rsd("pincode")
           TxtGArea.Text = Rsd("area")
           TxtGCity.Text = Rsd("city")
           TxtGState.Text = Rsd("state")
           TxtGCountry.Text = Rsd("country")

解决方案

verify that you have usercode column in Tbl_MstGuardian table.

May be column not exists or spelling mistake in column name.


The preferred way of fixing the error is to place a break point in the method on the statement which is just before where the error occurs, step through the code by each statement and verify the values using Watch window when the execution stops at the break point.


这篇关于如何解决索引超出范围的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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