Hi,
I had a problem when display the total amt from sql to textbox
------------------------------
create table get(Currentdate varchar(200),Expenses varchar(200),Amount decimal(38,2))-this a table
------------------------------
asp.net codings
--------------------------
mycomm.CommandText = "SELECT sum(Amount) from get"

dr = mycomm.ExecuteReader
While dr.Read()
TextBox6.Text = dr.GetDecimal(2)

End While
dr.Close()

--------------------------------------------------------------
Error:
Index was outside the bounds of the array.
how i rectify the error
Thanks in advance

Recommended Answers

All 4 Replies

Try:

TextBox6.Text = dr(0).ToString

I don't know VB, so however the syntax is supposed to be I have no clue, but this is the idea.

Because you're only selecting a single field, the reader only has that field, so it's at index 0 as far as the reader is concerned.

commented: ya,ur code works well.The error was solved +0

Hi,
I had a problem when display the total amt from sql to textbox
------------------------------
create table get(Currentdate varchar(200),Expenses varchar(200),Amount decimal(38,2))-this a table
------------------------------
asp.net codings
--------------------------
mycomm.CommandText = "SELECT sum(Amount) from get"

dr = mycomm.ExecuteReader
While dr.Read()
TextBox6.Text = dr.GetDecimal(2)

End While
dr.Close()

--------------------------------------------------------------
Error:
Index was outside the bounds of the array.
how i rectify the error
Thanks in advance

TextBox6.Text = dr.GetDecimal(0)

because -- sum(Amount) is in 0 index..

ya,its worked.........i m so happy....
I take two days to rectify the error.
Thanks for ur reply

ya,its worked.........i m so happy....
I take two days to rectify the error.
Thanks for ur reply

Your Welcome and i am also happy that your problem is solved and its pleasure to help u and in future you will help me :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.