Display data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tigger
    New Member
    • May 2007
    • 37

    #1

    Display data

    Hi there,
    I need to get values from Access database and bind it to ThresholdLabel. I could not use the drag and drop method because i want the data to be displayed during button click event, not when the form loads. I have a field called AC250L from Threshold Database. So how do i go about doing that?
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by tigger
    Hi there,
    I need to get values from Access database and bind it to ThresholdLabel. I could not use the drag and drop method because i want the data to be displayed during button click event, not when the form loads. I have a field called AC250L from Threshold Database. So how do i go about doing that?

    Is it possible to explain your problem in point by point..

    Comment

    • tigger
      New Member
      • May 2007
      • 37

      #3
      Originally posted by hariharanmca
      Is it possible to explain your problem in point by point..
      Hey sorry for not making myself clear. My main aim is to select a name from the combo box and when i click a button(getButto n), it will display the threshold value for that particular person. I've managed to display the values on a label. Here's my code..

      Imports System.Data
      Imports System.Data.Ole Db
      Imports System.IO

      Public Class DatabaseProject


      Private Sub DatabaseProject _Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
      'TODO: This line of code loads data into the 'Actual_Databas eDataSet.Thresh old_Database' table. You can move, or remove it, as needed.
      Me.Threshold_Da tabaseTableAdap ter.Fill(Me.Act ual_DatabaseDat aSet.Threshold_ Database)

      End Sub

      Private Sub getButton_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles getButton.Click , AC250LLabel1.Cl ick

      Dim con As New OleDb.OleDbConn ection
      Dim ds As New DataSet
      Dim da As New OleDb.OleDbData Adapter
      Dim sql As String
      Dim cmd As OleDb.OleDbComm and

      con.ConnectionS tring = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=D:\BIE\A ctual Database.mdb;Je t OLEDB:Database Password=****"
      sql = "SELECT * FROM ThresholdDataba se"

      con.Open()

      cmd = New OleDb.OleDbComm and(sql, con)
      Dim dataAdapter As New OleDb.OleDbData Adapter(cmd)
      dataAdapter.Fil l(ds, "YourTableName" )

      Me.NameComboBox .DataSource = ds.Tables("Thre shold Database")

      da = New OleDb.OleDbData Adapter(sql, con)
      da.Fill(ds, "Actual_Databas e")

      con.Close()

      thresholdLabel. Text = ds.Tables("Actu al_Database").R ows(6).Item("AC 250L") & "dB"

      End Sub

      End Class


      However, when i display the data, i have to manually type which row and which item i want to retrieve it from. I don't know how to link it to my combo box. Thanks.

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        Originally posted by tigger
        Hey sorry for not making myself clear. My main aim is to select a name from the combo box and when i click a button(getButto n), it will display the threshold value for that particular person. I've managed to display the values on a label. Here's my code..

        Imports System.Data
        Imports System.Data.Ole Db
        Imports System.IO

        Public Class DatabaseProject


        Private Sub DatabaseProject _Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Actual_Databas eDataSet.Thresh old_Database' table. You can move, or remove it, as needed.
        Me.Threshold_Da tabaseTableAdap ter.Fill(Me.Act ual_DatabaseDat aSet.Threshold_ Database)

        End Sub

        Private Sub getButton_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles getButton.Click , AC250LLabel1.Cl ick

        Dim con As New OleDb.OleDbConn ection
        Dim ds As New DataSet
        Dim da As New OleDb.OleDbData Adapter
        Dim sql As String
        Dim cmd As OleDb.OleDbComm and

        con.ConnectionS tring = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=D:\BIE\A ctual Database.mdb;Je t OLEDB:Database Password=****"
        sql = "SELECT * FROM ThresholdDataba se"

        con.Open()

        cmd = New OleDb.OleDbComm and(sql, con)
        Dim dataAdapter As New OleDb.OleDbData Adapter(cmd)
        dataAdapter.Fil l(ds, "YourTableName" )

        Me.NameComboBox .DataSource = ds.Tables("Thre shold Database")

        da = New OleDb.OleDbData Adapter(sql, con)
        da.Fill(ds, "Actual_Databas e")

        con.Close()

        thresholdLabel. Text = ds.Tables("Actu al_Database").R ows(6).Item("AC 250L") & "dB"

        End Sub

        End Class


        However, when i display the data, i have to manually type which row and which item i want to retrieve it from. I don't know how to link it to my combo box. Thanks.

        I am not sure that you mean this. Let me assume

        You want to select a particular name in combo box text area

        so

        Code:
        sql = "SELECT * FROM ThresholdDatabase"
        just change this qry to


        Code:
        sql = "SELECT * FROM ThresholdDatabase where AC250L like ‘" & trim(ComboboxName.Text) & “’”

        and

        Code:
        thresholdLabel.Text = ds.Tables("Actual_Database").Rows(0).Item("AC250L") & "dB"

        Comment

        • tigger
          New Member
          • May 2007
          • 37

          #5
          Originally posted by hariharanmca
          I am not sure that you mean this. Let me assume

          You want to select a particular name in combo box text area

          so

          Code:
          sql = "SELECT * FROM ThresholdDatabase"
          just change this qry to


          Code:
          sql = "SELECT * FROM ThresholdDatabase where AC250L like ‘" & trim(ComboboxName.Text) & “’”

          and

          Code:
          thresholdLabel.Text = ds.Tables("Actual_Database").Rows(0).Item("AC250L") & "dB"
          Hey thanks for the reply. I tried putting in the query but it seems to have an error.
          da.Fill(ds, "Actual_Databas e") is highlighted and it says "Syntax error in FROM clause."

          Comment

          • hariharanmca
            Top Contributor
            • Dec 2006
            • 1977

            #6
            Originally posted by tigger
            Hey thanks for the reply. I tried putting in the query but it seems to have an error.
            da.Fill(ds, "Actual_Databas e") is highlighted and it says "Syntax error in FROM clause."

            ThresholdDataba se is a table name?

            because, the select Qurey will be like

            Code:
            select <field1>, <field2>, <field3>, <field4> from <Table Name> where <Condition>

            Comment

            • tigger
              New Member
              • May 2007
              • 37

              #7
              Originally posted by hariharanmca
              ThresholdDataba se is a table name?

              because, the select Qurey will be like

              Code:
              select <field1>, <field2>, <field3>, <field4> from <Table Name> where <Condition>
              I've already managed to solve the problem. Thanks. But i faced another problem. Each time i select a name in the combo box, it will appear twice and the previous name disappears. For example, i select John and click a button to display a value. When i go back to the combo box and want to select another name, i realized that John's name will appear twice. And the name before John will disappear.

              Comment

              • hariharanmca
                Top Contributor
                • Dec 2006
                • 1977

                #8
                Originally posted by tigger
                I've already managed to solve the problem. Thanks. But i faced another problem. Each time i select a name in the combo box, it will appear twice and the previous name disappears. For example, i select John and click a button to display a value. When i go back to the combo box and want to select another name, i realized that John's name will appear twice. And the name before John will disappear.
                I think the problem is with Load event of combo box. (if no problem, you can post it and let me Look-over to solve).

                Comment

                • tigger
                  New Member
                  • May 2007
                  • 37

                  #9
                  Originally posted by hariharanmca
                  I think the problem is with Load event of combo box. (if no problem, you can post it and let me Look-over to solve).
                  I don't face the problem anymore. Thanks a lot for your help. Appreciate it =)

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by tigger
                    I don't face the problem anymore. Thanks a lot for your help. Appreciate it =)
                    Could you fill us in briefly on how you resolved it? This could be useful if someone else comes along with the same problem. (Don't worry if it's something silly - we've all been there.)

                    Comment

                    Working...