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

本文关键字:位置 错误 | 更新日期: 2023-09-27 18:35:40

我正在尝试打开反馈表,但显示以下错误
"位置 0 处没有行。"我已经检查了数据库,此查询有一行"从 pernr = sap_empmst中选择 zzfname"

这是我的代码...

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;
}

请帮忙,提前感谢

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

试试这个

错误说您正在访问不存在的行,

始终使用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;
}

}
}