2013-04-22 69 views
-1
con.Open(); 
SqlDataAdapter da4 = new SqlDataAdapter("select * from tblbooking where bookid =(select max(bookid) from tblbooking)", con); 
DataSet ds4 = new DataSet(); 
pay = ds4.Tables[0].Rows[0]["costoftickets"].ToString(); 
Label4.Text = "Amount to Pay : " + pay + " INR."; 
da4.Fill(ds4); 
DetailsView1.DataSource = ds4; 
DetailsView1.DataBind(); 
con.Close(); 
+0

你可以調試ds4.Tables [0] .Rows.Count嗎? – dekdev 2013-04-22 21:12:43

回答

0

您在訪問其內容之前沒有填充DataSet,所以自然就沒有數據。

con.Open(); 
SqlDataAdapter da4 = new SqlDataAdapter("select * from tblbooking where bookid =(select max(bookid) from tblbooking)", con); 
DataSet ds4 = new DataSet(); 
da4.Fill(ds4); // this needs to go before accessing the data 
pay = ds4.Tables[0].Rows[0]["costoftickets"].ToString(); 
Label4.Text = "Amount to Pay : " + pay + " INR."; 
DetailsView1.DataSource = ds4; 
DetailsView1.DataBind(); 
con.Close(); 

請注意,如果您的查詢沒有返回任何數據,您仍可能會收到錯誤。

+0

抱歉,表中有7行。正確插入 – user2308599 2013-04-22 19:10:23