2014-12-21 81 views
0

我想顯示從我的gridview的4列到標籤的最後值,我不使用頁腳。我該怎麼做? 這是我的代碼,但它沒有奏效。顯示gridview的最後一個值

strcomm = "select DibayarPada, JumlahDiBayar, DibayarSebelum, JumlahBayaran from 

bil where NoIC='" + Session("icvalue") + "'" 

    comm = New SqlCommand(strcomm, conn) 

    dr = comm.ExecuteReader 

    dt2.Load(dr) 

    GridView5.DataSource = dt2 
    GridView5.DataBind() 

    dateakhirtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)(0).ToString() 
    dateakhirtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)(0).ToString() 
    totalakhirtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)(0).ToString() 
    tarikhtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)(0).ToString() 
    jumlahtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)(0).ToString() 

我真的不知道該怎麼做。

+0

哪部分休息? – Avijit

+0

@Avijit位於rows.count -1部分 –

+0

您遇到的錯誤是什麼? – Avijit

回答

0

實際的語法是ds.Tables(0)(ds.Tables(0).Rows.Count - 1)( 「colname的」),以獲得與列名的最後一排值爲 「colname的」

-1
dateakhirtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)("colname").ToString() 
totalakhirtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)("colname").ToString() 
tarikhtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)("colname").ToString() 
jumlahtxt.Text = ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1)("colname").ToString() 
+0

這是不正確的答案,因爲沒有列名像「colname」。它將通過一個例外。 – Avijit

相關問題