need help populating text boxes with data from sql

Discussion in 'ASP .Net' started by luna, Jan 27, 2004.

  1. luna

    luna Guest

    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=database"

    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.CloseConnection)

    While objDR.Read()

    'userid.Text = objDR("userid")

    surname1.Text = objDR("surname1")

    firstname1.Text = objDR("fname1")

    Title1 = objDR("title1")

    End While

    Page.DataBind()

    End If
    luna, Jan 27, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:NhuRb.317$...
    > 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=database"
    >
    > 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.CloseConnection)
    >
    > While objDR.Read()
    >
    > 'userid.Text = objDR("userid")
    >
    > surname1.Text = objDR("surname1")
    >
    > firstname1.Text = objDR("fname1")
    >
    > Title1 = objDR("title1")
    >
    > End While
    >
    > Page.DataBind()
    >
    > End If
    >
    >
    Mark Fitzpatrick, Jan 27, 2004
    #2
    1. Advertising

  3. luna

    luna Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:NhuRb.317$...
    > > 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=database"
    > >
    > > 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.CloseConnection)
    > >
    > > While objDR.Read()
    > >
    > > 'userid.Text = objDR("userid")
    > >
    > > surname1.Text = objDR("surname1")
    > >
    > > firstname1.Text = objDR("fname1")
    > >
    > > Title1 = objDR("title1")
    > >
    > > End While
    > >
    > > Page.DataBind()
    > >
    > > End If
    > >
    > >

    >
    >
    luna, Jan 27, 2004
    #3
  4. 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" <> wrote in message
    news:dbvRb.436$...
    > 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:NhuRb.317$...
    > > > 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=database"
    > > >
    > > > 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.CloseConnection)
    > > >
    > > > While objDR.Read()
    > > >
    > > > 'userid.Text = objDR("userid")
    > > >
    > > > surname1.Text = objDR("surname1")
    > > >
    > > > firstname1.Text = objDR("fname1")
    > > >
    > > > Title1 = objDR("title1")
    > > >
    > > > End While
    > > >
    > > > Page.DataBind()
    > > >
    > > > End If
    > > >
    > > >

    > >
    > >

    >
    >
    Mark Fitzpatrick, Jan 27, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z2c3Nw==?=
    Replies:
    3
    Views:
    698
    Eliyahu Goldin
    Aug 18, 2005
  2. Stefan Mueller
    Replies:
    5
    Views:
    12,347
    jamesxa
    Jun 16, 2009
  3. Lamine Darbouche

    Populating three list boxes from the database

    Lamine Darbouche, Oct 6, 2003, in forum: ASP General
    Replies:
    2
    Views:
    110
    Lamine Darbouche
    Oct 8, 2003
  4. alwaysonnet
    Replies:
    4
    Views:
    298
  5. Derk

    Populating Combo Boxes

    Derk, Mar 4, 2005, in forum: Javascript
    Replies:
    2
    Views:
    84
Loading...

Share This Page