会话相关的语法是否正确 [英] is it correct syntax for session Related

查看:52
本文介绍了会话相关的语法是否正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (!IsPostBack) {
			con.Open();
			cmd.Connection = con;

			for (j = 0; j <= Session.Keys.Count - 1; j++) {
				  a[j]=Session.Keys[j];

			}


我在Line下面得到了错误;
a [j] = Session.Keys [j];

异常详细信息:System.IndexOutOfRangeException:位置1没有行.

源错误:


第39行:标签l =默认值(标签);
第40行:l =(标签)v.FindControl("Label1");
第41行:l.Text = dt.Rows [ctr] ["Serial"] +.";
第42行:l =(标签)v.FindControl("Label2");
第43行:dt.Rows [ctr] ["question"] = l.Text;


源文件:e:\ Documents and Settings \ Administrator \ My Documents \ Visual Studio 2010 \ WebSites \ Subbu \ WebSite6 \ Default2.aspx.cs行:41

我在行下出现错误

l.Text = dt.Rows [ctr] ["Serial"] +.";


I got the error below Line;
a[j]=Session.Keys[j];

Exception Details: System.IndexOutOfRangeException: There is no row at position 1.

Source Error:


Line 39: Label l = default(Label);
Line 40: l = (Label)v.FindControl("Label1");
Line 41: l.Text = dt.Rows[ctr]["Serial"] + ".";
Line 42: l = (Label)v.FindControl("Label2");
Line 43: dt.Rows[ctr]["question"]=l.Text ;


Source File: e:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\WebSites\Subbu\WebSite6\Default2.aspx.cs Line: 41

i got Error below line

l.Text = dt.Rows[ctr]["Serial"] + ".";

推荐答案

数组a[]应该与,请先检查.
The array a[] should be as big as the Session.Keys, check that first.


第一个错误的解决方法:

您是否正确定义了a?我使用以下语法尝试了您的代码,并且该代码运行时没有任何错误.
Resolution for First Error:

Have you defined a properly? I tried your code with below syntax and it runs without any Error.
try
{
    string[] a = new string[]{};

    for (int j = 0; j <= Session.Keys.Count - 1; j++)
    {
        a[j] = Session.Keys[j];

    }
}
catch (Exception ex)
{
    string error = ex.Message;
}



第二个错误的解决方案:

调试代码并检查dt的值,该值不应为null.还要检查您从dt.Rows[ctr]["Serial"]获得的价值.



Resolution for Second Error:

Debug your code and check value of dt, it should not be null. Also check what value you are getting from dt.Rows[ctr]["Serial"].


这篇关于会话相关的语法是否正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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