|
-
Jan 14th, 2007, 11:36 PM
#1
Thread Starter
Junior Member
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,..
-
Jan 15th, 2007, 04:41 AM
#2
Fanatic Member
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 
-
Jan 15th, 2007, 04:57 AM
#3
Thread Starter
Junior Member
Re: placed the result into textbox
into textbox, i also want take the data from database row by row
-
Jan 15th, 2007, 05:16 AM
#4
Fanatic Member
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:
DataReader = SqlCommand.ExecuteReader()
Dim index As Integer
While DataReader.Read()
TextBox1.Text += DataReader("nama") & controlchars.newline 'This will add whatever is in that column to a new line in the textbox
index += 1
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 
-
Jan 15th, 2007, 05:34 AM
#5
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...
-
Jan 15th, 2007, 06:19 AM
#6
Fanatic Member
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 
-
Jan 15th, 2007, 04:30 PM
#7
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:
'assuming datasource of datagrid is a set of records returned from a DB...
For Each rec As Common.DbDataRecord In MyDataGrid.DataSource
MessageBox.Show(rec(0).ToString) '1st column of data
Next
-
Jan 15th, 2007, 04:42 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|