2012-01-03 263 views
-1
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["GVRAgencyConnectionString1"].ConnectionString); 
      con1.Open(); 
      SqlDataAdapter da = new SqlDataAdapter("select  weight,mrp_pack,no_of_pack,mrp_master_pack from dbo.purchase_order where [email protected]_ID",con1); 
      da.SelectCommand.Parameters.AddWithValue("@product_ID", DropDownList3.Text); 
      DataTable dt = new DataTable(); 
      da.Fill(dt); 
      con1.Close();   
      DataRow row = dt.Rows[0]; 
      txtwgt.Text = row["weight"].ToString(); 
      txtmrpsinglepack.Text = row["mrp_pack"].ToString(); 
      txtnoofmasterpack.Text = row["no_of_pack"].ToString(); 
      txtmrpmaster.Text = row["mrp_master_pack"].ToString(); 
+0

這個錯誤意味着你的數據庫表'purchase_order'不含有'product_ID'等於在'選擇的值的任何記錄:

您可以嘗試訪問該行之前檢查此DropDownList3'。問題是什麼? – 2012-01-03 13:12:56

+0

你應該寫一些關於你想要做什麼,以及你的問題是什麼,而不是隻發佈一些代碼和錯誤消息。您顯示的錯誤消息實際上是您的情況中的預期結果。 – Guffa 2012-01-03 13:15:10

+0

謝謝你,先生,請幫助我先生,如果我需要編程幫助。 – 2012-01-04 07:50:03

回答

2

1)試試這個:

2)歡迎StackOverflow上。

3)如果你沒有女孩,你不能移動與一些女孩住在一起。

同樣在這裏 - 你不能在數據表withindex 0與記錄觸摸,如果你不知道你已經在索引中的行0

SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["GVRAgencyConnectionString1"].ConnectionString); 
      con1.Open(); 
      SqlDataAdapter da = new SqlDataAdapter("select  weight,mrp_pack,no_of_pack,mrp_master_pack from dbo.purchase_order where [email protected]_ID",con1); 
      da.SelectCommand.Parameters.AddWithValue("@product_ID", DropDownList3.Text); 
      DataTable dt = new DataTable(); 
      da.Fill(dt); 
      con1.Close();   
      if (dt.Rows.Count==0) return; 
      DataRow row = dt.Rows[0]; 
      txtwgt.Text = row["weight"].ToString(); 
      txtmrpsinglepack.Text = row["mrp_pack"].ToString(); 
      txtnoofmasterpack.Text = row["no_of_pack"].ToString(); 
      txtmrpmaster.Text = row["mrp_master_pack"].ToString(); 
1

你的結果是空的,所以有沒有行的全部數據表。

if (dt.Rows.Count > 0) { 
    ... 
} 
0
OracleConnection con = new OracleConnection(ConnectionString); 
string selectquery = "SELECT TITLE,DESCRIPTION,SEVERITY,STATUS,IMPACT,USER_NAME AS CREATED_BY ,CREATED_DATE FROM Issues A, USERS B Where A.CREATED_BY=B.USER_ID AND A.ISSUE_ID=" + ID; 
//string selectquery = "SELECT TITLE,DESCRIPTION,USER_NAME AS ASSIGNED_TO,SEVERITY,STATUS,IMPACT,USER_NAME AS CREATED_BY ,CREATED_DATE FROM Issues A, USERS B Where A.CREATED_BY=B.USER_ID AND A.ASSIGNED_TO=B.USER_ID AND A.ISSUE_ID=" + ID; 
OracleDataAdapter adp = new OracleDataAdapter(selectquery, con); 
DataTable dt = new DataTable(); 
adp.Fill(dt); 
//GridView1.DataSource = dt; 
// GridView1.DataBind(); 
lblTitle.Text = dt.Rows[0]["TITLE"].ToString(); 
lblDescription.Text = dt.Rows[0][1].ToString(); 
//lblSeverity.Text = dt.Rows[0][2].ToString(); 
lblStatus.Text = dt.Rows[0][3].ToString(); 
lblStatus.CssClass ="status"+ dt.Rows[0][3].ToString(); 
//lblImpact.Text = dt.Rows[0][4].ToString(); 
lblCreatedby.Text = dt.Rows[0][5].ToString(); 
lblcreateDate.Text = dt.Rows[0]["CREATED_DATE"].ToString(); 
//blCommentsDescriptionresult.Text = txtCommentdescription.Text;