question

WilfredEghenedji-9495 avatar image
0 Votes"
WilfredEghenedji-9495 asked WilfredEghenedji-9495 commented

Show all Records and Fields in Access-Db in a Textbox

Am creating a bible reference application, using Microsoft Office Access as Database. The point is, am able to code retrieving individual bible verse through its corresponding chapter, and show it on a textbox, but now wants to show all the records and fields in the access-db in a textbox, so that the bible can also be accessed as a whole in textbox. Is this possible? I have attempted, using the following:

 Dim command As OleDbCommand = New OleDbCommand()
 connection.Open()
 command.Connection = connection
 command.CommandText = "Select * from NewTestament
 Dim dr As OleDbDataReader = command.ExecuteReader()
    
 While dr.Read()
    LblBibleVerses2.Text = dr("*").ToString()
 End While
    
 dr.Close()
 connection.Close()

My fields in access db are: BibleReference and BibleReadings. Table name is 'NewTestament'

Thank you.


dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered WilfredEghenedji-9495 commented

Try something like this:

 . . .
 command.CommandText = "Select BibleReadings from NewTestament order by BibleReference"
 Dim dr As OleDbDataReader = command.ExecuteReader()
        
 While dr.Read()
     textbox1.AppendText( dr("BibleReadings").ToString( ) )
     textbox1.AppendText( Environment.NewLine )
 End While
 . . .

It assumes that BibleReference can be used in 'order by' to order the verses.



· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you very much for your response. After engaging the code, the outcome only shows the BibleReadings field (i.e. bible verse notes), leaving out the corresponding BibleReference field (i.e. the chapter and verse). This is more like reading a bible verse notes(For God so love the world...) without indicating its bible reference (i.e. John 3:16). What do you propose next? Thank you very much.

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 WilfredEghenedji-9495 ·

I propose this:

 . . .
 command.CommandText = "Select BibleReference, BibleReadings from NewTestament order by BibleReference"
 Dim dr As OleDbDataReader = command.ExecuteReader()
        
 While dr.Read()
     textbox1.AppendText( dr("BibleReference").ToString( ) )
     textbox1.AppendText( Environment.NewLine )
     textbox1.AppendText( dr("BibleReadings").ToString( ) )
     textbox1.AppendText( Environment.NewLine )
     textbox1.AppendText( Environment.NewLine )
 End While
 . . .

0 Votes 0 ·

Thanks bro. This solves it all.

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered WilfredEghenedji-9495 commented

I'm going to recommend a different approach, load data into a DataTable as per below.

 Public Class DatabaseOperations
     Public Function LoadNewTestament() As DataTable
    
         Using cn As New OleDbConnection("TODO")
             Using cmd As New OleDbCommand With {.Connection = cn}
                 cmd.CommandText = <SQL>
                     SELECT 
                         BibleReference, 
                         BibleReadings
                     FROM 
                         NewTestament
                     </SQL>.Value
    
                 Dim dt As New DataTable
             cn.Open()
             dt.Load(cmd.ExecuteReader)
                 Return dt
             End Using
         End Using
     End Function
    
 End Class


In your form, create a form level BindingSource, set the data source for the BindingSource to the DataTable above. Next create a ListBox or ComboBox, assign it's DataSource to the BindingList and DisplayMember to BibleReference. Next create a TextBox and use SomeTextBox.DataBinding.Add(...

Unsure if BibleReference or BibleReadings is the main property.

Now when you traverse items in the ListBox the TextBox shows the data for the selected ComboBox or ListBox item.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This works fine, but saved for subsequent use. Thank you very much!

0 Votes 0 ·