Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / May 2006

Tip: Looking for answers? Try searching our database.

How to display DataSet field in TextBox?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kvr901 - 28 May 2006 08:10 GMT
I created a DataSet in VS2005.  I want to fill a bunch of TextBoxes on a
Webform with the data, but for now will settle on 1 field of 1 record in 1
TextBox.  If I can accomplish that, then I should be able to do the rest.  
(Datagrids work fine with the dataset, but want to use TextBoxes).

The fieldname of the data I want is "fldLastName".  What do I need to do to
the below sub?  Thanks!

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
       
    Dim adapter As MyTestDataSet1TableAdapters.TestTable1TableAdapter = New
MyTestDataSet1TableAdapters.TestTable1TableAdapter()

       Me.TextBox1.Text =
End Sub
pvdg42 - 28 May 2006 22:21 GMT
>I created a DataSet in VS2005.  I want to fill a bunch of TextBoxes on a
> Webform with the data, but for now will settle on 1 field of 1 record in 1
[quoted text clipped - 14 lines]
>        Me.TextBox1.Text =
> End Sub

Study the class hierarchy under the DataSet class. What you have is a series
of collections that will allow you to drill down to the field you wish to
display in a given text box.
There is  (potentially) a collection of DataTable objects in a DataSet,
depending on the query(ies) used to populate the DataSet.
Within each DataTable, there is a DataRow collection. Each row represents a
record in the DataTable. There is also a DataColumn class that allows you to
identify the column in a given row to display.
Use these classes to isolate the field you want displayed.
kvr901 - 30 May 2006 17:32 GMT
Thank you for your reply, but I am so lost at this point that I need some
help with basics.  For now, I have given up on datasets, etc., and am trying
to use one "in-line" SQL statement to populate 3 textboxes.

I created a simple table named "TestTable1" with 3 fields.
Column Name      Type
fldPersonID          int
fldFirstName        nvarchar(50)
fldLastName         nvarchar(50)

There are 3 records:
1   GeorgeBush
2   Bill

What I have so far:

Dim testDataSource As New SqlDataSource()
testDataSource.ConnectionString =
ConfigurationManager.ConnectionStrings("TestDataConnectionString1").ToString()

       testDataSource.SelectCommandType = SqlDataSourceCommandType.Text
       testDataSource.SelectCommand = "SELECT fldPersonID, fldFirstName,
fldLastName FROM TestTable1"

       
       Me.txtboxPersonID.Text =
       Me.txtboxFirstName.Text =
       Me.txtboxLastNameName.Text =
kvr901 - 30 May 2006 17:44 GMT
Please disregard my previous reply.  I accidently posted it before finishing
it, and I can't find a way to edit it.

Thank you for your reply, but I am so lost at this point that I need some
help with basics.  For now, I have given up on datasets, etc., and am trying
to use one "in-line" SQL statement to populate 3 textboxes.

I created a simple table named "TestTable1" with 3 fields.
Column Name      Type
fldPersonID          int
fldFirstName        nvarchar(50)
fldLastName         nvarchar(50)

There are 3 records:
1   George       Bush
2   Bill         Clinton
3   Ronald       Reagan

At this point in time I don't care about parameters.  I don't care which
record
is displayed in the textboxes.  I just want to see how to get the data into
a textbox.

I have searched the net for days, but all I find is how to populate datagrids,
dataviews, datareaders, etc.  I want my data in textboxes.  

My connection string works fine, and I can query the data fine using
datagrids.

Any help would be appreciated.

What I have so far:

Dim testDataSource As New SqlDataSource()
testDataSource.ConnectionString =
ConfigurationManager.ConnectionStrings("TestDataConnectionString1").ToString()

       testDataSource.SelectCommandType = SqlDataSourceCommandType.Text
       testDataSource.SelectCommand = "SELECT fldPersonID, fldFirstName,
fldLastName FROM TestTable1"

       
       Me.txtboxPersonID.Text =
       Me.txtboxFirstName.Text =
       Me.txtboxLastNameName.Text =
pvdg42 - 31 May 2006 13:47 GMT
> Please disregard my previous reply.  I accidently posted it before
> finishing
[quoted text clipped - 44 lines]
>        Me.txtboxFirstName.Text =
>        Me.txtboxLastNameName.Text =

OK, and which of the three rows returned will be used to populate your text
boxes?
I'm hoping somebody else will jump into this thread, as all I have found is
bad news for you.
Basically, there is no "easy" way to populate the text boxes from any
in-memory representation of database data without writing the logic to
select a given field, convert that field to a String (if necessary), then
assign the string to the text property of a textbox.

I'm not at all sure you've simplified your problem by using the
SqlDataSource class:

Please read here:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource
(VS.80,d=ide).aspx


http://msdn2.microsoft.com/en-us/library/703tk8bc(d=ide).aspx

the SqlDataSource class is designed to fill complex controls with data, with
little or no coding. At a minimum, populating text boxes will require that
you either parameterize your SELECT query to limit rows returned to one,
then select columns for display in text boxes, or that you write the logic
to select the row in question from those in the returned dataset.

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource
(d=ide).aspx


You should also read this article explaining the DataSourceMode property:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource
.datasourcemode(d=ide).aspx

kvr901 - 31 May 2006 15:37 GMT
Perhaps I have not phrased my questions properly.

I might use datasets rather than the SQLDataSource (at this point I don't
know).

Regardless of what I use, my main question is:
How do I get the field data (be it from a SQL statement, or a stored
procedure, etc) into a TextBox?  For the sake of learning I can hard-code
parameters in the query, or even have only one record in the table.  Every
example I have seen is related to databound controls like Listboxes,
datagrids, etc.

TextBox1.Text =  (what does it equal?)  (how to I put the data here?)

TextBox1.Text = DataSet.fieldname?
TextBox1.Text = DataSet.Row.Fieldname?
TextBox1.Text =  Some other type of syntax?

And are there examples anywhere?  I have seen many examples using TextBoxes
to enter data that will be updated to a table, but I have not seen any
examples where the TextBox is used to display data.

I am not trying to display multiple records, so I am not interested in
datagrids.

Eventually (BUT NOT NOW) I plan to have multiple TextBoxes and multiple
DropDowns on a webform (probably 30 to 50 total) from which the user will
read, and edit data.  Right now all I need to figure out is how to put data
in a single query (or table) field into a TextBox.  I can write the VB code
if I can figure out how to display the data in the TextBox.

Thanks again.

> Basically, there is no "easy" way to populate the text boxes from any
> in-memory representation of database data without writing the logic to
[quoted text clipped - 3 lines]
> I'm not at all sure you've simplified your problem by using the
> SqlDataSource class:

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.