Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

I would like to ask about the problem of refreshing combo box. after combo box is bound to the database.

$
0
0

I wrote the code about refresh combo box data after COMBO BOX bind database

But I keep failing the data of refresh combo box. Below is mu code

 Public Function RetrieveRecords(ByVal strQuery As String) As DataSet

        Dim Ds As New DataSet()
        Dim conn As New OleDbConnection(GetConnectionString)
        Dim myDataAdapter As New OleDbDataAdapter(strQuery, conn)

        Try
            If conn.State = ConnectionState.Closed Then
                conn.Open()
            End If

            myDataAdapter.Fill(Ds)
            RetrieveRecords = Ds

        Catch ex As Exception
            'Log Error
        Finally
            myDataAdapter.Dispose()
            myDataAdapter = Nothing
            If conn.State = ConnectionState.Open Then
                conn.Close()
                conn.Dispose()
                conn = Nothing
            End If
            Ds.Dispose()
            Ds = Nothing
        End Try

    End Function

 

  Public Function IsRecordAvailable(ByVal tempDS As DataSet) As Boolean

        If tempDS IsNot Nothing Then
            If tempDS.Tables.Count > 0 Then
                If tempDS.Tables(0).Rows.Count > 0 Then
                    Return True
                Else
                    Return False
                End If
                Return False
            End If
        Else
            Return False
        End If

    End Function

       Dim strSQL As String
        Dim ds As DataSet
        Dim cf As New Common

        If txtCATEGORY.Text = Nothing Then
            MsgBox("Plss Fill Data Category")
            Exit Sub
        End If

        strSQL = "INSERT INTO tbl_Category ([Category]) "
        strSQL = strSQL + "VALUES('" & Me.txtCATEGORY.Text & "')"
        txtCATEGORY.Text = ""

        Select Case MsgBox("Did you sure you want to save this data", MsgBoxStyle.YesNo,"Message Confirmation")
            Case MsgBoxResult.Yes
                cnn.Open()
                MessageBox.Show("Your data have been save successful","Message")
            Case MsgBoxResult.No
                MessageBox.Show("You no save this data", "Message")
                Exit Sub
        End Select

        ds = cf.RetrieveRecords(strSQL)

        If cf.IsRecordAvailable(ds) Then
            For intLoop As Integer = 0 To ds.Tables(0).Rows.Count - 1
                txtCATEGORY.Items.Add(ds.Tables(0).Rows(intLoop).Item(0))
                txtCATEGORY1.Items.Add(ds.Tables(0).Rows(intLoop).Item(0))


            Next
        End If

Code Refresh Combo box

       Dim strSQL As String
        Dim ds As DataSet
        Dim cf As New Common

        If txtCATEGORY.Text = Nothing Then
            MsgBox("Plss Fill Data Category")
            Exit Sub
        End If

        strSQL = "INSERT INTO tbl_Category ([Category]) "
        strSQL = strSQL + "VALUES('" & Me.txtCATEGORY.Text & "')"
        txtCATEGORY.Text = ""

        Select Case MsgBox("Did you sure you want to save this data", MsgBoxStyle.YesNo,"Message Confirmation")
            Case MsgBoxResult.Yes
                cnn.Open()
                MessageBox.Show("Your data have been save successful","Message")
            Case MsgBoxResult.No
                MessageBox.Show("You no save this data", "Message")
                Exit Sub
        End Select

        ds = cf.RetrieveRecords(strSQL)

        Dim da As New OleDbDataAdapter
        Dim dt As New DataTable
        da.SelectCommand = New OleDbCommand("select * from tbl_Category", cnn)
        txtCATEGORY.DataSource = (dt)
        txtCATEGORY.ValueMember = "Category"

        If cf.IsRecordAvailable(ds) Then
            For intLoop As Integer = 0 To ds.Tables(0).Rows.Count - 1
                txtCATEGORY.Items.Add(ds.Tables(0).Rows(intLoop).Item(0))
                txtCATEGORY1.Items.Add(ds.Tables(0).Rows(intLoop).Item(0))


            Next
        End If

can someone give me commend and any advise 


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>