2014-12-31 52 views
0

我想打開反饋窗體,但顯示下面的錯誤
「位置0沒有行。 我已經檢查數據庫中,有一排此查詢「選擇從sap_empmst其中PERNR = zzfname」雖然打開頁面出現錯誤,但位置0處沒有行

這裏是我的代碼...

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

您是否調試過代碼?你是否從會話中獲得了userId的值? –

+0

你可以在adp.fill(ds)處放置一個斷點,看看sqlstr的內容是什麼。然後嘗試在SQL中執行相同的查詢 – Thangadurai

+0

@RahulSingh yes首先有一個登錄頁面從此頁面用戶標識重定向到反饋頁面。 –

回答

1

試試這個

錯誤表示您正在訪問的行已不存在的話,

經常檢查行是否存在in DataSet/DataTable using RowCount

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


} 

} 
+0

現在得到錯誤 編譯錯誤 描述:在編譯爲請求提供服務所需的資源時發生錯誤。請查看以下具體的錯誤細節並適當修改您的源代碼。 編譯器錯誤消息:CS1001:標識符預期 源錯誤: 38行:\t \t { 第39行: 線40:\t \t \t串zzfname = ds.Tables [0] .Rows [0] 。[ 「zzfname」]的ToString(); Line 41:\t \t Label2_name.Text = zzfname; 42行:\t \t} –

+0

您是否使用了斷點?我認爲錯誤是由於其他一些reasons.Error是不特定 –

+0

太感謝你了上述解決方案工作.... –

相關問題