Hi everyone, I am trying to retrieve data row by row from my SQL Server and load them into my respective textboxes, I was doing the below code but of course it doesn't work as the For Each loop will load every single textboxes with each data retrieved, ran out of ideas. Appreciate if someone can give me a boost here. Thanks.
Code:Private Sub retrieve_Data() Dim con As New SqlConnection Dim cmd As New SqlCommand ' Dim icounter As Integer = 1 Try con.ConnectionString = "Data Source=HPEnvy-HP; Initial Catalog=Cinema; User Id=sa; Password=8034615h;" con.Open() cmd.Connection = con cmd.CommandText = "SELECT [movie_ID], [movie_Title] FROM [Movie_Table] ORDER BY [MOVIE_ID] " Dim lrd As SqlDataReader = cmd.ExecuteReader() While lrd.Read() Dim reader As String = lrd(1).ToString Dim arrLoad As New ArrayList arrLoad.Add(lrd(1).ToString) For i = 0 To arrLoad.Count - 1 For Each cCtrl As Control In Panel1.Controls If TypeOf cCtrl Is TextBox Then Dim txtBox As New TextBox txtBox = cCtrl txtBox.Text = arrLoad.Item(i) End If Next Next End While Catch ex As Exception MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records") Finally con.Close() End Try End Sub




Reply With Quote
