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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO.NET return a single value

Status
Not open for further replies.

Turpis

Programmer
Apr 16, 2002
151
0
0
I can find all types of awesome examples for databinding. But I just want to take a single distinct value from my dataset and put it into a textbox with no databinding.

Something like this:
me.textbox.text = myreturned_value_from_a_dataset

I have 3 books on .NET and even one that is only for ADO.NET and all they focus on is databinding.

If I need to set my adapter's SELECT statement to return the single value...how do I get that single value out of the dataset?

I am confused.

Charles
Quality Assurance/Developer
 
Charles

A dataset contains datatables, which can have table names.
Each DataTable has DataRows.

To access the datarow do something like this
Code:
'A Datarow is basically a record in a Table
dim dr as Datarow = ds.tables("Table1").rows(0)
'Now you can access the Datarow fields
dim s1 as String = dr.item("field1")
textbox1.text = s1

Sweep
...if it works dont mess with it
 
Dim conn As New SqlConnection
Dim command As New SqlCommand
conn.ConnectionString = "integrated security=SSPI;data " & _
"source=JOHNNB1;initial catalog=Northwind"

command.CommandText = "Select CompanyName from Customers " & _
"Where CustomerId = 'ALFKI'"
command.Connection = conn
conn.Open()
Dim sCompName As String = CType(command.ExecuteScalar, String)
MessageBox.Show(sCompName)
conn.Close()
 
Thank you both (SqueakinSweep & johnCronin). I can see applications for both of those answers, depending on whether I already have the data in a dataset or not.

Charles
Quality Assurance/Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top