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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.