Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox

Status
Not open for further replies.

dutch09

Programmer
Feb 27, 2009
1
I have a datagrid on a web form populated from a sql database table; no problem there. On the same form I have a textbox that I'd like to populate with the 'sum' value of one of the table's fields. Seems simple enough. I don't seem to have any errors in the code, just no output to the textbox. Where is my error? Can someone point me in the right direction?

Protected Sub ytdFuel_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ytdFuel.TextChanged
Dim sql
Dim SumOfQuantity As New Integer
sql = "SELECT Sum(Quantity) As SumOfQuantity FROM Fuel"
Me.ytdFuel.Text = ("[SumOfQuantity]")
End Sub
 
Perhaps that your code is confused or even don't have time to display the result since the value will (maybe) continuously pulled from the database. See, you assign the textbox's value on its TextChanged event.

It's just a thought.
 
Being in a TextChanged event, wouldn't the value of Me.ytdFuel.text have to be changed before this event would be triggered?
 

I hate to point the obvious, but…
you declare [tt]sql[/tt] (As Object? You do not state the Type) and declare the [tt]SumOfQuantity[/tt]

Then you assign the value to the Object [tt]sql[/tt], which is a String [tt]“SELECT Sum(Quantity) As SumOfQuantity FROM Fuel”[/tt], looks to me like a request from DB, but it may be [tt]“I would like a donut”[/tt] as well, because it is not used anywhere in the code.

Then, you assign some value to [tt]ytdFuel.Text[/tt], which is supposed to come from... Where?

Well, at least that’s what I see in your code.

How do you connect to your database?
Do you populate any tables in any data sets?
DO you use a DataReader to get data from your DB?


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top