Results 1 to 8 of 8

Thread: placed the result into textbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    placed the result into textbox

    i use visual studio, n microsoft sql server, so my connection to database is like below:

    Dim sqlCon As SqlConnction=New SqlConnection()
    Dim myDataAdapter As SqlDataAdapter
    Dim DS DataSet
    SqlConn.ConnectionString="Data Source =NORA; Initial Catalog=Account; UserId=sa; Password=password;"

    sqlConn.Open()

    Dim queryString As String=SELECT nama FROM pelajar WHERE ......

    MyDataAdapter=New SqlDataAdapter(queryString,sqlConn)

    sqlConn.close()

    my answer is, i want the result from database example (nama) is assign into one variable like (Dim name As String), and i want the value of name is placed into textbox.

    so can all of u show me how to write the code to generate it,..

  2. #2
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: placed the result into textbox

    Just to clear this up...do you want the result stored in a textbox or in a variable? It sounds like you are going to need to use a dataReader.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    Re: placed the result into textbox

    into textbox, i also want take the data from database row by row

  4. #4
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: placed the result into textbox

    Ok well you need to set up a DataReader. I've found this example code, it should give you what you need to perform the task you require. Its best if you attempt the code yours;ef first and then come back to us with any questions or problems you have.

    VB Code:
    1. DataReader = SqlCommand.ExecuteReader()
    2.             Dim index As Integer
    3.             While DataReader.Read()
    4.                 TextBox1.Text += DataReader("nama")  & controlchars.newline 'This will add whatever is in that column to a new line in the textbox
    5.                 index += 1
    6.             End While

    Just a quick note. You will have to have the multiline property of the textbox enabled to allow you to add each result on a new line

    This is the website i got the code from....you may find answers to any other questions you have here.

    Hope this helps

    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: placed the result into textbox

    Depending on your situation, if you already have the data in a dataset, then you can loop through the dataset to get the information you need as well. Datareaders shouldn't be "required" to do what you are wanting, but your response of "taking data row by row" might have led Kimmy to suggest that...

  6. #6
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: placed the result into textbox

    Yeah thats why i suggested a DataReader. I dont really know much about using the dataset to get data...can u go through that row by row? If not then how does it go through and retrieve the required data?
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: placed the result into textbox

    I guess it would depend on the type of datasource you are using, but for instance, if you have a datasource of records from a db, you could do something like below...
    VB Code:
    1. 'assuming datasource of datagrid is a set of records returned from a DB...
    2. For Each rec As Common.DbDataRecord In MyDataGrid.DataSource
    3.       MessageBox.Show(rec(0).ToString) '1st column of data
    4. Next

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: placed the result into textbox

    The decision seems like it should be based on what you want to do with the data next. A datareader will be faster than a dataset, since it is a read only pipe, but if you want to write...well, then a datareader wouldn't be so good.

    However, why are you putting multiple items into a textbox? A listbox or listview seem a more reasonable receptacle for multiple items.
    My usual boring signature: Nothing

Posting Permissions

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



Click Here to Expand Forum to Full Width