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

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by amitshrivas
1

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.

Votes + Comments
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..

0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.