0

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???

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Exelio
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.