View Single Post
Old 12-13-2017, 09:06 AM
starmanMike starmanMike is offline
Junior Contributor
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 310
Default basic advice please re

Hi, having very recently started with I am having a couple of problems with databases, not least the terminology! But am I right in thinking that a data adapter sort of equals a vb6 data control and a dataset = recordset? Also, not sure how to access the fields in the dataset. So far I have this:
Module modDB
    Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =" & frmDatabase.thedb)
    Dim sql As String

    Public Sub Searchforstar(db As String, thestar As String)
        sql = "SELECT * FROM starcharts where starname = ' " & thestar & "'"
        Dim dataadapter As New OleDb.OleDbDataAdapter(sql, con)
        Dim ds As New DataSet()
        Dim foundrow() As Data.DataRow
        foundrow = ds.Tables("charts").Rows(0).Item("starname")
        If foundrow.Length = 0 Then
            MsgBox("Star is not in the database")

            'display the details in the text boxes. One example below for testing purposes...
            frmDatabase.txtVariable.Text = ds.Tables("charts").Rows(0).Item("starname")
'even though there will only ever be one row returned.

        End If
    End Sub
End Module
So if the user (say) enters a typo that's not in the data set they get the message box, otherwise the text boxes get filled with the results from the appropriate field. I don't want design-time data binding because I need the text boxes empty to start with.
I have experimented putting a typo in the text box and hitting a button (which calls the above sub) and I do indeed get the message box. However if I do enter a valid search term nothing happens.
Reply With Quote