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

Hi, having very recently started with vb.net I am having a couple of problems with databases, not least the terminology! But am I right in thinking that a vb.net 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:
Code:
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()
        con.Open()
        dataadapter.Fill(ds)
        con.Close()
        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")
        Else

            '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