954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem retrive data by ID

i hv using vb.net create the form to insert the data to ms Sql server database...
now i want to get data from database base on the ID key in by user....

Dim sqlCommand As New SqlCommand("Select * form NewPatient Where PID = '"& txtPID.Text &"'", SqlConnection1)

Dim myReader As SqlDataReader = sqlCommand.ExecuteReader
' myReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)

While (myReader.Read())

txtName.Text = myReader("PName").ToString()
txtIC.Text = myReader("NoIC").ToString()
txtAge.Text = myReader("Age").ToString()
txtGender.Text = myReader("Gender").ToString()
txtRace.Text = myReader("Race").ToString()
txtStatus.Text = myReader("Status").ToString()
txtOccupation.Text = myReader("Occupation").ToString()

End While

but why no data out???

ohohling
Newbie Poster
7 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

hi,
Since you are using vb.net,there are some changes to be made in the code.

while myReader.Read
txtName.Text = myReader("PName").ToString
txtIC.Text = myReader("NoIC").ToString
txtAge.Text = myReader("Age").ToString
txtGender.Text = myReader("Gender").ToString
txtRace.Text = myReader("Race").ToString
txtStatus.Text = myReader("Status").ToString
txtOccupation.Text = myReader("Occupation").ToString
end while


try this
Hope this helps

Regards

Exelio

Exelio
Junior Poster in Training
57 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You