Sub FillListControl(ByVal ctrl As ListControl, ByVal cn As IDbConnection, ByVal tableName As String, ByVal textField As String, ByVal valueField As String)
' Open the connection if necessary.
If cn.State = ConnectionState.Closed Then cn.Open()
Dim cmd As IDbCommand = cn.CreateCommand
cmd.CommandText = String.Format("SELECT {0},{1} FROM {2}", textField, valueField, tableName)
Dim dr As IDataReader = cmd.ExecuteReader
' Bind the control.
ctrl.DataSource = dr
ctrl.DataTextField = textField
ctrl.DataValueField = valueField
ctrl.DataBind()
' Close the DataReader.
dr.Close()
End Sub
Sub ShowTitleInfo(ByVal titleId As String)
' Read info on a specific title.
If cn.State = ConnectionState.Closed Then cn.Open()
Dim cmd As New SqlCommand("SELECT * FROM Titles WHERE title_id='" & titleId & "'", cn)
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleRow)
' Fill all controls on the form.
dr.Read()
txtTitle.Text = dr("title").ToString
txtPrice.Text = dr("price").ToString
txtType.Text = dr("type").ToString
' Display the correct element in the ddlPublishers control.