SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict jlisec01's Avatar
    Join Date
    Nov 2006
    Location
    MI
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    displaying results from database

    hi there, i had just a quick question, inside the head section of my web page I have the following code:

    Code VBNET:
    Sub getSData(s as Object, e As EventArgs)
            Dim objConn As OleDbConnection
    	Dim objCmd As OleDbCommand
    	Dim objRdr As OleDbDataReader
     
            objConn = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &server.mappath("\access_db\sysDB.mdb"))
            objCmd = New OleDbCommand("SELECT * FROM Student", objConn)
            objConn.Open()
            objRdr = objCmd.ExecuteReader()
            While objRdr.Read()
              Response.Write(objRdr.Item("Name") & "<br />")
            End While
            objRdr.Close()
            objConn.Close()
    End Sub

    then I have a button that calls this function, it works 100% but the results are displayed towards the top of the page, and my question is how could I get the results to display where I want on the page? for instance the middle of the page? thanks for any help.

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jlisec01 View Post
    ... it works 100&#37; but the results are displayed towards the top of the page, and my question is how could I get the results to display where I want on the page? for instance the middle of the page? thanks for any help.
    Don't use Response.Write. Assign it to the .Text value of an <asp:literal> on the page instead.

  3. #3
    SitePoint Addict jlisec01's Avatar
    Join Date
    Nov 2006
    Location
    MI
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NAWA-mark View Post
    Don't use Response.Write. Assign it to the .Text value of an <asp:literal> on the page instead.
    many thanks, I used the following in the script:

    Code VBNET:
    lblNames.Text = objRdr.Item("Name") & "<br />"

    and in the body I have:

    Code VBNET:
    <asp:literal id="lblNames" runat="server"/>

    but when I click the button to submit it, it just displays the very last name in the database, any ideals? thanks again.

  4. #4
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jlisec01 View Post
    ... but when I click the button to submit it, it just displays the very last name in the database, any ideals? thanks again.
    You are overwriting it each time. Try this instead
    Code VBNET:
    lblNames.Text += objRdr.Item("Name") & "<br />"
    I'm pretty sure the += works the same in VB.NET as it does in C#. If not do the old school version
    Code VBNET:
    lblNames.Text = lblNames.Text & objRdr.Item("Name") & "<br />"

  5. #5
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You should also consider a repeater or listview or one of the other databindables depending on what you're really after.

    Databindables? Is that even a word? lol

  6. #6
    SitePoint Addict jlisec01's Avatar
    Join Date
    Nov 2006
    Location
    MI
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol, many thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •