2
Contributors
1
Reply
8
Views
3 Years
Discussion Span
Last Post by Sulaiman_1
0

Datareader needs an opened database connection.
Its an Connected Oriented Architecture
example

Private Sub loop_QTY()
        Dim sql As String = "SELECT Item_Qty from tbl_Products WHERE Item_Name = '" & cbo_Items.Text & "' "

        Dim cmd As New OleDbCommand(sql, con)
        Dim dr As OleDbDataReader

        cbo_QTY.Items.Clear()
        con.Open()
        dr = cmd.ExecuteReader()
        While dr.Read()
            cbo_QTY.Items.Add(dr(0))
        End While
        con.Close()
    End Sub

Dataadapter does not need an Open Database connection
Its an Disconnected Access

 Dim dt As New DataTable
Dim da As New SqlDataAdapter("select * from data", cn)
da.Fill(dt)
For Each row As DataTable In ds.Tables("data").Rows
If row(0).ToString = ComboBox1.Text Then
TextBox3.Text = dt.Rows(0)("type").ToString()
TextBox4.Text = dt.Rows(1)("shape").ToString()
TextBox5.Text = dt.Rows(2)("size").ToString()
TextBox6.Text = dt.Rows(3)("place").ToString()
TextBox7.Text = dt.Rows(1)("weight").ToString()
TextBox3.ReadOnly = True
TextBox4.ReadOnly = True
TextBox5.ReadOnly = True
TextBox6.ReadOnly = True
TextBox7.ReadOnly = True
Exit For
End If
Next
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.