Outputing query Question

fadedkeil

Member
Joined
Feb 8, 2009
Messages
12
Programming Experience
Beginner
VB.NET:
    Dim con As New OleDb.OleDbConnection
    Dim da As New OleDb.OleDbDataAdapter
    Dim ds As New DataSet
    Dim cm As New OleDb.OleDbCommand
    Dim read As OleDb.OleDbDataReader
    Dim sql As String
VB.NET:
  Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
 con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\proj\Module_1_Encoder\Module_1_Encoder\enrollment.mdb"
        con.Open()
        sql = "SELECT * FROM tblOld Where Studnum=" & StudNumMaskedTextBox.Text & ""
        cm.Connection = con
        cm.CommandText = sql
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "tblOld")
        read = cm.ExecuteReader
        read.Read()
        txtFName.Text = read.Item("FName")
        txtLName.Text = read.Item("LName")
        con.Close()
but the there's no output even if i put a while loop on the read.read help please how can i out put it on the textboxes the selected records on the query.
 
Why are you filling your dataset PLUS executing the command objects exectutereader?

Of course this doesnt answer the question of whether your query works in the first place, but no need to fill two objects with the same data.
 
Not working

I really need to populate my textboxes with the data that is selected by this query but how?
VB.NET:
"SELECT * FROM tblOld Where Studnum=" & StudNumMaskedTextBox.Text & ""
its vs 2008 btw:confused:
 
Attach your dataset to a datagridview to see if any records are being returned.

VB.NET:
        [COLOR="Blue"]Dim [/COLOR]strDbConnection [COLOR="blue"]As String [/COLOR]= ""

        strDbConnection = [COLOR="Red"]"Provider=Microsoft.Jet.OLEDB.4.0; " & _
                                  "Data Source=D:\proj\Module_1_Encoder\" & _
                                  "Module_1_Encoder\enrollment.mdb[/COLOR]"

        [COLOR="blue"]Using [/COLOR]con [COLOR="blue"]As New[/COLOR] OleDb.OleDbConnection(strDbConnection)
            [COLOR="Blue"]Dim [/COLOR]da [COLOR="Blue"]As [/COLOR]OleDb.OleDbDataAdapter
            [COLOR="blue"]Dim [/COLOR]strSql [COLOR="blue"]As String [/COLOR]= [COLOR="red"]"SELECT * FROM tblOld Where Studnum = "[/COLOR] & _
                                    CInt(StudNumMaskedTextBox.Text)

            [COLOR="seagreen"]'DA will open & close connection when needed[/COLOR]
            da = [COLOR="blue"]New [/COLOR]OleDb.OleDbDataAdapter(strSql, con)
            da.Fill(ds, "tblOld")

            [COLOR="seagreen"]'Just to view the returned records[/COLOR]
            DataGridView1.DataSource = ds.Tables("[COLOR="red"]tblOld[/COLOR]")

            [COLOR="blue"]If [/COLOR]ds.Tables("[COLOR="red"]tblOld[/COLOR]").Rows.Count > 0 [COLOR="blue"]Then[/COLOR]
                txtFName.Text = ds.Tables("[COLOR="red"]tblOld[/COLOR]").Rows(0)("[COLOR="Red"]FName[/COLOR]").ToString
                txtLName.Text = ds.Tables("[COLOR="red"]tblOld[/COLOR]").Rows(0)("[COLOR="red"]LName[/COLOR]").ToString
            [COLOR="blue"]End If[/COLOR]
            [COLOR="seagreen"]'Using block will close & dispose of the object[/COLOR]
        [COLOR="blue"]End Using[/COLOR]
 

Latest posts

Back
Top