Working with ComboBox

Imports System.Data
Imports
System.Data.SqlClient
Imports
System.IO
Public
Class Form4
   
Dim ConnUrl As TextReader
   
Dim ConnString As String
    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
   
Handles  MyBase.Load
       
Dim ds As New DataSet
        ConnUrl =
New StreamReader("C:\Documents and Settings\Administrator\My
       
Documents\Visual Studio 
        2005\Projects\CnFromTxt\CnFromTxt\ConnectionURL.txt")
        ConnString = ConnUrl.ReadToEnd()
        ds = GetCompany()
       
If ds.Tables.Count > 0 Then
            If ds.Tables(0).Rows.Count > 0 Then
                cmbCustomerId.Items.Clear()
               
For Each oRow As DataRow In ds.Tables("CUSTOMERS").Rows
                cmbCustomerId.Items.Add(oRow.Item(
"CUSTOMERID"))
               
Next
                cmbCustomerId.SelectedIndex = 0
                lblRecords.ForeColor = System.Drawing.Color.Red
                lblRecords.Text =
"Selected Records:" & "[ " & cmbCustomerId.SelectedIndex + 1 & " ]"
            Else
                MsgBox("No data found", MsgBoxStyle.Information)
           
End If
        End If
   
End Sub
    Private Function GetCompany() As DataSet
       
Dim Sconnection As SqlConnection = Nothing
        Dim da As SqlDataAdapter = Nothing
        Dim ds As New DataSet
       
Dim strQry As String
        strQry = "SELECT CUSTOMERID FROM CUSTOMERS "
        Try
            Sconnection = New SqlConnection(ConnString)
            da =
New SqlDataAdapter(strQry, Sconnection)
            da.Fill(ds,
"CUSTOMERS")
       
Catch ex As Exception
            MsgBox(ex.Message)
       
End Try
        Return ds
   
End Function

   
Private Sub cmbCustomerId_SelectedIndexChanged(ByVal sender As System.Object, ByVal
   
As  System.EventArgs) Handles cmbCustomerId.SelectedIndexChanged
       
Dim Sconnection As SqlConnection = Nothing
        Dim da As SqlDataAdapter = Nothing
        Dim ds As New DataSet
       
Dim strQry As String
        lblRecords.Text = "Selected Records:" & "[ " & cmbCustomerId.SelectedIndex + 1 & " ]"
        strQry = " SELECT COMPANYNAME,CONTACTNAME,CONTACTTITLE,ADDRESS + '   ' + 'City:'" +
       
vbCrLf
        strQry = strQry +
" + CITY + '   ' " + vbCrLf
        strQry = strQry +
" + 'Region:' " + vbCrLf
        strQry = strQry +
" + ISNULL(REGION,'Not Mentioned') " + vbCrLf
        strQry = strQry +
" + '   ' + 'Postal Code:'+ ISNULL(POSTALCODE,'Not Mentioned') " + vbCrLf
        strQry = strQry +
" + '   ' + 'Country:' + ISNULL(COUNTRY,'NOT MENTIONED')  " + vbCrLf
        strQry = strQry +
" + '   ' + 'Phone Number:' + ISNULL(PHONE,'Not Mentioned') " + vbCrLf
        strQry = strQry +
" + '   ' + 'Fax Number:' + ISNULL(FAX,'Not Mentioned')AS ADDRESS FROM
       
CUSTOMERS WHERE CUSTOMERID='" &   
        Trim(cmbCustomerId.Text) & "' "
        Try
            Sconnection = New SqlConnection(ConnString)
            da =
New SqlDataAdapter(strQry, ConnString)
            da.Fill(ds)
           
If ds.Tables.Count > 0 Then
                If ds.Tables(0).Rows.Count > 0 Then
                    txtCompany.Text = IIf(IsDBNull(ds.Tables(0).Rows(0).Item("COMPANYNAME")), "",
                   
ds.Tables(0).Rows(0).Item ("COMPANYNAME"))
                    txtEmployee.Text = IIf(IsDBNull(ds.Tables(0).Rows(0).Item(
"CONTACTNAME")), "",
                   
ds.Tables(0).Rows(0).Item ("CONTACTNAME"))
                    txtAddress.Text = IIf(IsDBNull(ds.Tables(0).Rows(0).Item(
"Address")), "",
                   
ds.Tables(0).Rows(0).Item ("Address"))
                    txtCname.Text = IIf(IsDBNull(ds.Tables(0).Rows(0).Item(
"CONTACTTITLE")), "",
                   
ds.Tables(0).Rows(0).Item ("CONTACTTITLE"))
               
End If
            Else
                MsgBox("No data found", MsgBoxStyle.Information)
           
End If
        Catch ex As Exception
            MsgBox(ex.Message)
       
End Try

   
End Sub
End
Class