Showing posts with label datasource. Show all posts
Showing posts with label datasource. Show all posts

Friday, March 16, 2012

Populating a textbox with a datasource

I have a textbox that needs to get it's value from database based on a value parsed from text in another textbox.

I am using a datasource with a select command to hit the database, but I have no need to collect anything but a single value, so it seems very wasteful to have to load anything into a dataset or the like, just to get that one thing to a textbox.

What's the easiest way to get this one value for the textbox?

thanks

Did you thought keep the data in a Session variable?

Your select command should similar to below

SELECT ID FROM table WHERE ID='1'

Now you could use one SqlCommand.ExecuteScalar which only returns 1 value from the database.

Check below link for more information

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

HC


rsegecin:

Did you thought keep the data in a Session variable?

That wouldn't do much because I wouldstill have to do all the fetching to get itinto the session variable, or any other variable for that matter.


Haissam:

Your select command should similar to below

SELECT ID FROM table WHERE ID='1'

Now you could use one SqlCommand.ExecuteScalar which only returns 1 value from the database.

Check below link for more information

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

HC

Yes that is very similar to the SQL I'm using

I was considering ExecuteScalar thought, the drawback is really that it's still a lot of code for one little value, and I have been reusing the datasources pretty religiously so far, eliminating the need for much code at all.

I'm hoping to keep that up, but maybe there is no particularly simple way... I wish datasources had a Scalar command that returned the value :/

Populating ComboBox From Dataset

Hi Guys,

I need to populate a combobox from a dataset returned from a webservice. I set the datasource property of the control to the web method but got an empty list at run time! What am I doing wrong? Any help on how to achieve this? Looping through a datareader solved the problem but I want to consume a dataset from a web service. I thought this would be a straight stuff but I'm having problems with it.After setting the datasource property you have to bind the data to your controll.

It seems you are missing that bit.
I can handle that with DropDownList control in ASP.Net but not with ComboBox in Windows Application! Could you kindly show how syntactically?
Are you getting an error?
What does it say?

Post your code so that we can see more clearly what has gone wrong
I am not getting any error message! I only get this wierd entry in the ComboBox. "System.Data.DataViewManagerListItemTypeDescriptor"

This is the code that I used.

Private Sub Users_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim wsDemo As New ng_app001_pc_stock.PCInventory
ComboBox1.datasource = wsDemo.getAllOSTypes
End Sub

The webmethod getAllOSTypes works well, at least I tested it with DataGrid control. What could be wrong?