得到错误“索引在数组的边界之外".在C#中 [英] Getting an error "index was outside the bounds of the array" in C#

查看:115
本文介绍了得到错误“索引在数组的边界之外".在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

try
        {
            bool check = ValidStudent(TBRNo.Text);

//after executing above statement program jumps up to the catch block n raise d exception

            if (check == false)
            {
                SqlDataReader dr = FetchDetails_frmString(TBRNo.Text);
                DataTable dt = new DataTable();
                
                dt.Load(dr);
                Session["dr"] = dr;
                Session["FetchDetails_frmString"] = dt;
                con.Close();
                if (dt.Rows.Count > 0)
                {
                    string ip = GetIpAddress();
                    int i = StoreIpAddress(ip, TBRNo.Text);
                    if (i > 0)
                    {
                        ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('Login Successful!')", true);
                        Response.Redirect("~/Student/home.aspx");
                    }
                    else
                    { 
                        
                    }
                   
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('Access Denied.....This string does not exist')", true);
                }
            }
           else
            {
                ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('You have Already login this Website')", true);
            }
        }
        catch (Exception o)
        {
            Label8.Text = o.Message;
            ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('Access Denied.....Some Problem occured')", true);
        }
        finally 
        { 
            con.Close();         
        }

推荐答案

看起来像问题出在ValidStudent()函数不在此代码中
look like Problem is in ValidStudent() function not in this code



您需要发布
Hi,
you need to publish
ValidStudent(TBRNo.Text);


代替其他功能.

为了获得帮助,您可以检查数组索引是否为负或小于预期.


funtion instead of others.

for a help can you check your array index is negative or less than expected.

array.length=5;
if index < array.length
return array[index]



像那样.我认为您需要在ValidStudent(TBRNo.Text);
中修复它 或将收益分配给布尔值时.只需检查一下即可获得修复.



like that. i think you need to fix it inside the ValidStudent(TBRNo.Text);
or when you assign the return to the bool. Just check it and you get fix.
good luck.


在TBRNo文本框中输入的数字大于数组/数据集/表等中的记录数.这就是为什么您遇到此异常的原因.
The number entered in the TBRNo textbox is more than the number of record in the array/dataset/table etc. Thats why your are getting this exception.


这篇关于得到错误“索引在数组的边界之外".在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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