i have problem with my database.i using combobox to select elements. i have store the data using ms excess.the problem is when i select one of the element in the combobox.For example when i choose Perlis from the combobox, i hit summary button, there is no output on the label just under summart button.

Imports System.Data.OleDb
Public Class Form4
    Inherits System.Windows.Forms.Form
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim icount As Integer
    Dim str As String

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim Form1 As New Form1
        Form1.Show()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim Form5 As New Form5
        Form5.Show()
        Me.Hide()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim Form6 As New Form6
        Form6.Show()
        Me.Hide()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim con As New OleDbConnection
        Dim com As New OleDbCommand

        con.ConnectionString = "tblPlace"
        com.Connection = con
        com.CommandText = "SELECT * FROM tblPlace"
        con.Open()

        Dim da As New OleDbDataAdapter(com)
        Dim ds As New DataSet
        da.Fill(ds, "tblPlace")

        Dim theDataRowArray() As DataRow = Nothing

        If ComboBox1.SelectedItem = "sabah" Then
            theDataRowArray = Me..Tables("tblPlace").Select("state='PERAK'", "state", DataViewRowState.CurrentRows)
            If (theDataRowArray.Length = 1) Then
                lblSummary.Text = CStr(theDataRowArray(0)("<column1state>")) 'here instead of <clomun3name> put the name of the third column
            Else
                lblSummary.Text = "Nothing Found!"
            End If

        End If

        con.Close()

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click

    End Sub
End Class

Dani AI

Generated

The code posted by will not update the label because several separate issues prevent any row from being found or displayed. was right to flag the ComboBox check — that is one problem, but there are other important bugs to fix (connection string, dataset reference, filter mismatch and placeholder column name).

Key problems to correct

  • con.ConnectionString = "tblPlace" is invalid; the connection string must point to the Access file and a provider. See the OleDbConnection.ConnectionString guidance for correct formats (OleDbConnection.ConnectionString).
  • The code fills a DataSet but then uses Me..Tables("tblPlace") (syntax error). Use the dataset instance: ds.Tables("tblPlace") or query the database directly. See DataTable.Select rules for filtering (DataTable.Select).
  • The If ComboBox1.SelectedItem = "sabah" Then check can fail: SelectedItem may be Nothing, an object, or a DataRowView if the ComboBox is data-bound. Use ComboBox1.Text or CType(ComboBox1.SelectedItem, DataRowView)("state").ToString() when bound. See ComboBox.SelectedItem docs (ComboBox.SelectedItem).
  • The filter uses 'PERAK' while the ComboBox checks for 'sabah' — values must match. Replace <column1state> with the real column name and test for Rows.Count > 0 instead of Length = 1.

Practical, minimal approach
Use a parameterized query to fetch the desired value and avoid loading the entire table:

Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Path\To\Db.accdb;"
Dim sql As String = "SELECT TOP 1 PlaceName FROM tblPlace WHERE state = ?"

Using con As New OleDbConnection(connString)
    Using cmd As New OleDbCommand(sql, con)
        cmd.Parameters.AddWithValue("?", ComboBox1.Text)
        con.Open()
        Dim result = cmd.ExecuteScalar()
        lblSummary.Text = If(result IsNot Nothing, result.ToString(), "Nothing Found!")
    End Using
End Using

Debug checklist

  • Confirm ComboBox1.Text contains the expected value or, if bound, use SelectedValue/DataRowView.
  • After filling a dataset check ds.Tables.Count and ds.Tables("tblPlace").Rows.Count.
  • Wrap DB calls in Try/Catch and log exceptions.
    These changes address the immediate failures and make the lookup robust and maintainable.

Recommended Answers

All 2 Replies

The way what your written as wrong

If ComboBox1.SelectedItem = "sabah" Then

So whenever user selects as "sabah" then you are doing some set of statements. Until unless its not going inside to get the any output regarding the Summary.

Change your logic and try it.

tyvm.will try it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.