TextBox and SQL Data

Discussion in 'ASP .Net Web Controls' started by dave, Dec 4, 2003.

  1. dave

    dave Guest

    Hi

    Could someone please show me an example (vb pref) of how the hell you get
    data into a text box??

    I have a sub that is called on the page_load which connects to a DB and
    returns one row of data, which i then want to use to populate the textboxes
    on a form (details editing page).

    Everything i have tried doesnt seem to work??

    Here is the code for getting the data:

    Sub BindUserData( )
    Dim myConnection as New
    SqlConnection(ConfigurationSettings.AppSettings("DBconnString"))
    dim strSQL as String = "SELECT * FROM dbo.USERS WHERE dbo.USERS.ID = 1"
    Dim myCommand as New SqlCommand(strSQL, myConnection)
    Dim myDA as New SqlDataAdapter()
    myDA.SelectCommand = myCommand
    Dim myDS as New DataSet()
    myDA.Fill(myDS)
    End Sub


    Also what is the best thing to use? Datareader or Dataset or Dataview, etc

    Thanks in advance....
     
    dave, Dec 4, 2003
    #1
    1. Advertising

  2. dave

    Axel Dahmen Guest

    Hi, Dave,

    this is your mistake: In your code there is not a single line assigning the
    data you're reading to any TextBox. That's what's missing. You just filled
    an array (the DataTable) with DB data and left it there.

    To copy the array's contents into any TextBox, just write something like:

    Dim txtBox As System.Web.UI.WebControls.TextBox ' created by VS.NET

    ...

    txtBox.Text = myDS.Tables(0).Rows(0)(0) ' put this into the PageLoad
    function

    HTH,
    Axel Dahmen


    -----------------------------
    "dave" <> schrieb im Newsbeitrag
    news:...
    > Hi
    >
    > Could someone please show me an example (vb pref) of how the hell you get
    > data into a text box??
    >
    > I have a sub that is called on the page_load which connects to a DB and
    > returns one row of data, which i then want to use to populate the

    textboxes
    > on a form (details editing page).
    >
    > Everything i have tried doesnt seem to work??
    >
    > Here is the code for getting the data:
    >
    > Sub BindUserData( )
    > Dim myConnection as New
    > SqlConnection(ConfigurationSettings.AppSettings("DBconnString"))
    > dim strSQL as String = "SELECT * FROM dbo.USERS WHERE dbo.USERS.ID = 1"
    > Dim myCommand as New SqlCommand(strSQL, myConnection)
    > Dim myDA as New SqlDataAdapter()
    > myDA.SelectCommand = myCommand
    > Dim myDS as New DataSet()
    > myDA.Fill(myDS)
    > End Sub
    >
    >
    > Also what is the best thing to use? Datareader or Dataset or Dataview, etc
    >
    > Thanks in advance....
    >
    >
     
    Axel Dahmen, Dec 6, 2003
    #2
    1. Advertising

  3. dave

    dave Guest

    Thank Axel

    I just didnt post the textbox assignment code i was trying in my previous
    post, as that was the part i couldnt get working properly.

    Thanks again,

    What is the advantage/disadvantage between using a datareader, or a dataset
    to populate edits, etc. Obv it is better to use a dataset when populating a
    datagrid, but is there any benefits of using it to return a single record to
    populate the edits?

    Cheers





    "Axel Dahmen" <> wrote in message
    news:...
    > Hi, Dave,
    >
    > this is your mistake: In your code there is not a single line assigning

    the
    > data you're reading to any TextBox. That's what's missing. You just filled
    > an array (the DataTable) with DB data and left it there.
    >
    > To copy the array's contents into any TextBox, just write something like:
    >
    > Dim txtBox As System.Web.UI.WebControls.TextBox ' created by VS.NET
    >
    > ...
    >
    > txtBox.Text = myDS.Tables(0).Rows(0)(0) ' put this into the

    PageLoad
    > function
    >
    > HTH,
    > Axel Dahmen
    >
    >
    > -----------------------------
    > "dave" <> schrieb im Newsbeitrag
    > news:...
    > > Hi
    > >
    > > Could someone please show me an example (vb pref) of how the hell you

    get
    > > data into a text box??
    > >
    > > I have a sub that is called on the page_load which connects to a DB and
    > > returns one row of data, which i then want to use to populate the

    > textboxes
    > > on a form (details editing page).
    > >
    > > Everything i have tried doesnt seem to work??
    > >
    > > Here is the code for getting the data:
    > >
    > > Sub BindUserData( )
    > > Dim myConnection as New
    > > SqlConnection(ConfigurationSettings.AppSettings("DBconnString"))
    > > dim strSQL as String = "SELECT * FROM dbo.USERS WHERE dbo.USERS.ID = 1"
    > > Dim myCommand as New SqlCommand(strSQL, myConnection)
    > > Dim myDA as New SqlDataAdapter()
    > > myDA.SelectCommand = myCommand
    > > Dim myDS as New DataSet()
    > > myDA.Fill(myDS)
    > > End Sub
    > >
    > >
    > > Also what is the best thing to use? Datareader or Dataset or Dataview,

    etc
    > >
    > > Thanks in advance....
    > >
    > >

    >
    >
     
    dave, Dec 6, 2003
    #3
  4. dave

    Axel Dahmen Guest

    My personal favoured is the DataReader as at any time it only contains one
    single data row whereas the DataTable contains the whole result set, which
    is quite memory and time consumptive, particularly on big result sets.

    The only drawback on DataReaders is that you can only use one per
    connection, which might become a programming challenge here and there.

    Best wishes,
    Axel Dahmen

    -------------
    "dave" <> schrieb im Newsbeitrag
    news:...
    > Thank Axel
    >
    > I just didnt post the textbox assignment code i was trying in my previous
    > post, as that was the part i couldnt get working properly.
    >
    > Thanks again,
    >
    > What is the advantage/disadvantage between using a datareader, or a

    dataset
    > to populate edits, etc. Obv it is better to use a dataset when populating

    a
    > datagrid, but is there any benefits of using it to return a single record

    to
    > populate the edits?
    >
    > Cheers
    >
    >
    >
    >
    >
    > "Axel Dahmen" <> wrote in message
    > news:...
    > > Hi, Dave,
    > >
    > > this is your mistake: In your code there is not a single line assigning

    > the
    > > data you're reading to any TextBox. That's what's missing. You just

    filled
    > > an array (the DataTable) with DB data and left it there.
    > >
    > > To copy the array's contents into any TextBox, just write something

    like:
    > >
    > > Dim txtBox As System.Web.UI.WebControls.TextBox ' created by VS.NET
    > >
    > > ...
    > >
    > > txtBox.Text = myDS.Tables(0).Rows(0)(0) ' put this into the

    > PageLoad
    > > function
    > >
    > > HTH,
    > > Axel Dahmen
    > >
    > >
    > > -----------------------------
    > > "dave" <> schrieb im Newsbeitrag
    > > news:...
    > > > Hi
    > > >
    > > > Could someone please show me an example (vb pref) of how the hell you

    > get
    > > > data into a text box??
    > > >
    > > > I have a sub that is called on the page_load which connects to a DB

    and
    > > > returns one row of data, which i then want to use to populate the

    > > textboxes
    > > > on a form (details editing page).
    > > >
    > > > Everything i have tried doesnt seem to work??
    > > >
    > > > Here is the code for getting the data:
    > > >
    > > > Sub BindUserData( )
    > > > Dim myConnection as New
    > > > SqlConnection(ConfigurationSettings.AppSettings("DBconnString"))
    > > > dim strSQL as String = "SELECT * FROM dbo.USERS WHERE dbo.USERS.ID =

    1"
    > > > Dim myCommand as New SqlCommand(strSQL, myConnection)
    > > > Dim myDA as New SqlDataAdapter()
    > > > myDA.SelectCommand = myCommand
    > > > Dim myDS as New DataSet()
    > > > myDA.Fill(myDS)
    > > > End Sub
    > > >
    > > >
    > > > Also what is the best thing to use? Datareader or Dataset or Dataview,

    > etc
    > > >
    > > > Thanks in advance....
    > > >
    > > >

    > >
    > >

    >
    >
     
    Axel Dahmen, Dec 6, 2003
    #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. Luqman
    Replies:
    0
    Views:
    476
    Luqman
    Jan 21, 2006
  2. Harry Zoroc
    Replies:
    1
    Views:
    963
    Gregory Vaughan
    Jul 12, 2004
  3. tanmaypatankar
    Replies:
    0
    Views:
    1,091
    tanmaypatankar
    Dec 18, 2007
  4. ecoolone
    Replies:
    0
    Views:
    782
    ecoolone
    Jan 3, 2008
  5. faniccj
    Replies:
    0
    Views:
    1,801
    faniccj
    Feb 12, 2011
Loading...

Share This Page