Display values in ComboBox using Disconnected Architecture


Hi All, This is code for working with data sets in disconnected architecture…..
 
 
Public Class FrmAdd
    Private Sub FrmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillDesignations()
    End Sub
 
    Private Sub FillDesignations()
        Dim objCommand As SqlCommand
        Dim objDa As New DataAccess
        Dim sqlADP As New SqlDataAdapter
        Try
            objDa.OpenDB()
            objCommand = New SqlCommand("Select * from tblDesignations", objDa.ObjCon)
            Dim objDS As New DataSet
            sqlADP.SelectCommand = objCommand
            sqlADP.Fill(objDS)
            objDa.CloseDB()
            If objDS.Tables.Count <> 0 Then
                If cmbDesignations.Items.Count <> 0 Then
                    cmbDesignations.Items.Clear()
                End If
                If objDS.Tables(0).Rows.Count <> 0 Then
                    cmbDesignations.DataSource = objDS.Tables(0).DefaultView
                    cmbDesignations.DisplayMember = objDS.Tables(0).Columns(1).ColumnName
                    cmbDesignations.ValueMember = objDS.Tables(0).Columns(0).ColumnName
                End If
            End If
          
        Catch ex As Exception
        End Try
    End Sub
 
    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        ‘If Not Me.txtFirstName.Text.Trim() Is Nothing Or Me.txtLastName.Text Is Nothing Then
        Dim objCommand As SqlCommand
        Dim objDa As New DataAccess
        Try
            objCommand = New SqlCommand()
            Dim strQuery As String = "Insert into tblEmployees (FirstName,LastName,DesignationID) Values(‘" & txtFirstName.Text & "’,’" & txtLastName.Text & "’, " & cmbDesignations.SelectedValue & ")"
            ”, EmailAddress,CellNumber,City,Country
            objCommand.CommandText = strQuery
            objDa.OpenDB()
            objCommand.Connection = objDa.ObjCon
            objCommand.ExecuteNonQuery()
            objDa.CloseDB()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
 
        ‘ End If
    End Sub
 
    Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
        Dim Control As Control
        For Each Control In Me.Controls
            If TypeOf Control Is TextBox Then
                Control.Text = ""
            End If
        Next
    End Sub
End Class
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: