-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();
4

1 回答 1

0

在访问数据集的内容之前,您还没有填充数据集,因此其中自然没有数据。

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();

请注意,如果您的查询没有返回数据,您仍然可能会遇到错误。

于 2013-04-22T18:50:21.787 回答