473,385 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

need help populating text boxes with data from sql

theres no errors in my code - but it does nothing at all - its supposed to
be populating text boxes!!
any ideas ? (im am pretty new to all this)

If Not Page.IsPostBack Then

Dim search As String

Dim strConn As String =
"server=Gringotts;uid=sa;pwd=password;database=dat abase"

Dim sql As String = "Select * from table where ID = " + userid.Text.ToString

Dim conn As New System.Data.SqlClient.SqlConnection(strConn)

Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)

Dim objDR As System.Data.sqlclient.SqlDataReader

conn.Open()

objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)

While objDR.Read()

'userid.Text = objDR("userid")

surname1.Text = objDR("surname1")

firstname1.Text = objDR("fname1")

Title1 = objDR("title1")

End While

Page.DataBind()

End If
Nov 18 '05 #1
3 1551
Have you made sure that you are actually getting results back? The While
objDR.Read() loop will only occur while the datareader is reading, hence, if
there is nothing to read then the textboxes will not be loaded. Where is the
value for the userid.Text value coming from? Is it from a label? If it's
from a label that the user fills out, then presses a submit button to load
the data, then none of this will even happen because the IF statement is
making sure that the only time the code is executed is when the page first
loads. If this happens because of a user submitting then omit the Not in the
if statement because you want it to only occur when the page is posting
back. You also need to put something in there to make sure that there is a
valid userid in the textbox.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"luna" <lu**@themoon.com> wrote in message
news:Nh******************@newsfep2-gui.server.ntli.net...
theres no errors in my code - but it does nothing at all - its supposed to
be populating text boxes!!
any ideas ? (im am pretty new to all this)

If Not Page.IsPostBack Then

Dim search As String

Dim strConn As String =
"server=Gringotts;uid=sa;pwd=password;database=dat abase"

Dim sql As String = "Select * from table where ID = " + userid.Text.ToString
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)

Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)

Dim objDR As System.Data.sqlclient.SqlDataReader

conn.Open()

objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)

While objDR.Read()

'userid.Text = objDR("userid")

surname1.Text = objDR("surname1")

firstname1.Text = objDR("fname1")

Title1 = objDR("title1")

End While

Page.DataBind()

End If

Nov 18 '05 #2
You seem to misunderstand

i checked the SQL server and I know that there is data in there - definatley

im sure that the problem is something to do with

while objDR.Read()
surname1.text = objdr("surname1")
************************ <---- here never gets touched when code is running
end while
I have hardcoded the SQL statement at the moment so that it looks like this:

Dim sql As String = "Select * from Personal where Personal.ID=2"

the thing that is annoying me is that the software seems to run perfectly
well, I dont get any error messages but it also doesnt
put anything into the textboxes or labels that i would like

any help that you could give me with this would be greatly appreciated

Mark.


"Mark Fitzpatrick" <ma******@fitzme.com> wrote in message
news:OA**************@TK2MSFTNGP11.phx.gbl...
Have you made sure that you are actually getting results back? The While
objDR.Read() loop will only occur while the datareader is reading, hence, if there is nothing to read then the textboxes will not be loaded. Where is the value for the userid.Text value coming from? Is it from a label? If it's
from a label that the user fills out, then presses a submit button to load
the data, then none of this will even happen because the IF statement is
making sure that the only time the code is executed is when the page first
loads. If this happens because of a user submitting then omit the Not in the if statement because you want it to only occur when the page is posting
back. You also need to put something in there to make sure that there is a
valid userid in the textbox.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"luna" <lu**@themoon.com> wrote in message
news:Nh******************@newsfep2-gui.server.ntli.net...
theres no errors in my code - but it does nothing at all - its supposed to be populating text boxes!!
any ideas ? (im am pretty new to all this)

If Not Page.IsPostBack Then

Dim search As String

Dim strConn As String =
"server=Gringotts;uid=sa;pwd=password;database=dat abase"

Dim sql As String = "Select * from table where ID = " +

userid.Text.ToString

Dim conn As New System.Data.SqlClient.SqlConnection(strConn)

Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)

Dim objDR As System.Data.sqlclient.SqlDataReader

conn.Open()

objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)

While objDR.Read()

'userid.Text = objDR("userid")

surname1.Text = objDR("surname1")

firstname1.Text = objDR("fname1")

Title1 = objDR("title1")

End While

Page.DataBind()

End If


Nov 18 '05 #3
I do understand. Having valid data in the database doesn't mean anything.
That's actually one of the worste ways to think when designing something
that queries the database as having data in the db is only a small part of
the battle. One of the things that happens often is the query that is sent
to the database is not exactly what you think it is. When this is the case,
it doesn't matter what data is in the database. Always try dumping your SQL
statement in testing before it is passed to the db to the browser or trace
through response.write() or trace.write(). This avoids a lot of unnecessary
tinkering sometimes as it's easy to keep working on the wrong things. In
this case, if you had dumped the sql string you would have noticed it wasn't
getting anything through the response.write when you clicked the button to
submit the userid because of the not page.ispostback condition

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"luna" <lu**@themoon.com> wrote in message
news:db******************@newsfep2-gui.server.ntli.net...
You seem to misunderstand

i checked the SQL server and I know that there is data in there - definatley
im sure that the problem is something to do with

while objDR.Read()
surname1.text = objdr("surname1")
************************ <---- here never gets touched when code is running end while
I have hardcoded the SQL statement at the moment so that it looks like this:
Dim sql As String = "Select * from Personal where Personal.ID=2"

the thing that is annoying me is that the software seems to run perfectly
well, I dont get any error messages but it also doesnt
put anything into the textboxes or labels that i would like

any help that you could give me with this would be greatly appreciated

Mark.


"Mark Fitzpatrick" <ma******@fitzme.com> wrote in message
news:OA**************@TK2MSFTNGP11.phx.gbl...
Have you made sure that you are actually getting results back? The While
objDR.Read() loop will only occur while the datareader is reading, hence,
if
there is nothing to read then the textboxes will not be loaded. Where is the
value for the userid.Text value coming from? Is it from a label? If it's
from a label that the user fills out, then presses a submit button to load the data, then none of this will even happen because the IF statement is
making sure that the only time the code is executed is when the page first loads. If this happens because of a user submitting then omit the Not in

the
if statement because you want it to only occur when the page is posting
back. You also need to put something in there to make sure that there is a valid userid in the textbox.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"luna" <lu**@themoon.com> wrote in message
news:Nh******************@newsfep2-gui.server.ntli.net...
theres no errors in my code - but it does nothing at all - its

supposed to be populating text boxes!!
any ideas ? (im am pretty new to all this)

If Not Page.IsPostBack Then

Dim search As String

Dim strConn As String =
"server=Gringotts;uid=sa;pwd=password;database=dat abase"

Dim sql As String = "Select * from table where ID = " +

userid.Text.ToString

Dim conn As New System.Data.SqlClient.SqlConnection(strConn)

Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)

Dim objDR As System.Data.sqlclient.SqlDataReader

conn.Open()

objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)

While objDR.Read()

'userid.Text = objDR("userid")

surname1.Text = objDR("surname1")

firstname1.Text = objDR("fname1")

Title1 = objDR("title1")

End While

Page.DataBind()

End If



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
7
by: Andrew McKendrick | last post by:
Hi, I've noticed a bug in VB.NET (latest .NET Framework)... - I have a TabControl on a form with several tabs. - Each tab contains text boxes that are bound to fields in a data source...
2
by: Bill Brinkworth | last post by:
in vb.net 2005, i would like to pull up a name from a database (customers) (i can do this already), then after a name is selected from a combox box, to populate the form's text boxes with with data...
4
by: jim | last post by:
So I've had my knuckles rapped by a pro who can offer only vauge advice. I need to reduce the size of one of my tables. Here is the scene: I'm trying to track lots of test scores for individual...
1
by: emmaruwa | last post by:
I have a form with two text boxes (in its details section) that pull data from two fields in my database table. This same form also has a button beside the text boxes which is supposed to open...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
4
by: Andrew Meador - ASCPA, MCSE, MCP+I, Network+, A+ | last post by:
I have created a report. This report needs to display records between two dates entered by the user. I put two text boxes on the report so I can enter the start and end date - I set them to use an...
2
by: JonWB | last post by:
Hi, I am very new to .Net and have recently taken over someone else’s project. I am developing an asp webpage using C#. I have an asp:table that is populated using data from a database....
11
by: jgoodnight | last post by:
Hi, I have a form with three combo boxes: Area, Sub-Area, and Factor. I've set up the Sub-Area combo box to list only those areas that are part of the selected area. I've set up the Factor combo...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.