简体   繁体   English

打开页面时出现错误,位置0没有行

[英]while opening the page getting error there is no row at position 0

I am trying to open feedback form but showing below error 我正在尝试打开反馈表,但显示以下错误
"There is no row at position 0." “位置0没有行。” I have already checked database, there is a row for this query "select zzfname from sap_empmst where pernr = " 我已经检查了数据库,该查询有一行“从sap_empmst选择zzfname,其中pernr =”

Here is my code... 这是我的代码...

public partial class feedback : System.Web.UI.Page
{
DataAccess Getdata=new DataAccess();
OracleConnection con = new OracleConnection("Data Source=cluster;User ID=ocgpis;Password=pisocg;unicode=true");
OracleConnection con1 = new OracleConnection("Data Source=oragc;User ID=ipcltos;Password=ipcltos;unicode=true");
//OracleConnection con = new OracleConnection("Data Source=10.127.240.231/ocgpis;User ID=ocgpis;Password=pisocg;unicode=true");
//OracleConnection con1 = new OracleConnection("Data Source=10.127.240.216/ipcldb;User ID=ipcltos;Password=ipcltos;unicode=true");
OracleConnection con2 = new OracleConnection("Data Source=cluster;User ID=RGSS;Password=RGSS;unicode=true");
string strMessage = ""; int mins_now = 0;
protected void Page_Load(object sender, EventArgs e)
{
    Label1_pl.Text = Session["UserID"].ToString();
    string sqlstr = "select zzfname from sap_empmst where pernr = '" +  Label1_pl.Text + "'";
    DataSet ds = new DataSet();
    OracleDataAdapter adp = new OracleDataAdapter(sqlstr, con1);
    adp.Fill(ds);
    string zzfname = ds.Tables[0].Rows[0].ItemArray[0].ToString();
    Label2_name.Text = zzfname;
}

Please help, thanks in advance 请帮助,在此先感谢

Try this 尝试这个

Error Says that Your are accessing a row which is Not present so, 错误说您正在访问的行不存在,

Always Check For whether Row exists in DataSet/DataTable using RowCount 始终使用RowCount检查DataSet/DataTable是否存在行

protected void Page_Load(object sender, EventArgs e)
{

if(!Page.IsPostBack)
{
    Label1_pl.Text = Session["UserID"].ToString();
    string sqlstr = "select zzfname from sap_empmst where pernr = '" +  
    Label1_pl.Text + "'";
    DataSet ds = new DataSet();
    OracleDataAdapter adp = new OracleDataAdapter(sqlstr, con1);
    adp.Fill(ds);

    if(ds!=null)
    if(ds.Tables[0].Rows.Count>0)
{
    string zzfname = ds.Tables[0].Rows[0]["zzfname"].ToString();
    Label2_name.Text = zzfname;
}


}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM