how to use datareader

Joined
May 11, 2005
Messages
5
Programming Experience
Beginner
i want to read data firstname and lastname from sql and display in a textbox

and after that i want to update that textbox how to do that my backend is sql. thanx
 
Last edited:
Joined
May 11, 2005
Messages
5
Programming Experience
Beginner
kulrom said:
update that textbox
could you explain this please? Maybe you want to update db if you change something within certain textbox?

Kind regards :)

btw, you said only SQL ... but didn't point out which DB type you are using there ... MS Access, MSSQL ....

my back end is sql
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,334
Location
Sydney, Australia
Programming Experience
10+
I assume you mean that your back end is SQL Server and you want to update the database if the value in the TextBox has changed. If these assumptions are true, I personally would recommend using an SqlDataAdapter to Fill a DataTable, to which you can bind your TextBoxes. When the Text in the databound Controls is updated, so too are the values in the DataTable. You can then use the SqlDataAdapter to Update the database from the DataTable.
 

ManicCW

Well-known member
Joined
Jul 21, 2005
Messages
428
Location
Mostar
Programming Experience
Beginner
Datareader

Dim cnPodaci As New SqlConnection
cnPodaci.ConnectionString = "Database Path"
cnPodaci.Open()
Dim cm As New SqlCommand
cm.CommandText = "SELECT * FROM TABLE"
cm.Connection = cnPodaci
Dim dr As SqlDataReader
dr = cm.ExecuteReader

If dr.HasRows Then

dr.Read()
me.txtBox.text = dr.Item("ColumnName")

dr.Close()

End If
cnPodaci.Close()

- to update that record you would have to use direct UPDATE command.
UPDATE Table SET ....
... parameters ...
executenonquery
 

tharshi

New member
Joined
Jun 3, 2008
Messages
1
Programming Experience
Beginner
Dim cnPodaci As New SqlConnection
cnPodaci.ConnectionString = "Database Path"
cnPodaci.Open()
Dim cm As New SqlCommand
cm.CommandText = "SELECT * FROM TABLE"
cm.Connection = cnPodaci
Dim dr As SqlDataReader
dr = cm.ExecuteReader

If dr.HasRows Then

dr.Read()
me.txtBox.text = dr.Item("ColumnName")

dr.Close()

End If
cnPodaci.Close()

- to update that record you would have to use direct UPDATE command.
UPDATE Table SET ....
... parameters ...
executenonquery

but when i give the code it is telling syntax error.
what is the problem?
 
Top Bottom