Local variable assAdapter already declared in block?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bill

    Local variable assAdapter already declared in block?

    Does anyone see why I'm getting this message? It errors out on line 5 at
    "assAdapter "?
    Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
    "data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
    2008\IT_Assets. mdb")

    Dim assAdapter As OleDb.OleDbData Adapter

    Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
    asset_tag=?")

    assCmd.Paramete rs.Add("asset_t ag", OleDbType.VarCh ar).Value = cboAsset.Text

    Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)

    Dim assDT As New DataTable

    'Release the instances of the above objects

    assAdapter.Fill (assDT)

    assAdapter.Disp ose()


  • Jack Jackson

    #2
    Re: Local variable assAdapter already declared in block?

    This is exactly the same problem you had in the previous example.

    Either remove the first Dim (the best solution), or change the second
    one to just an assignment statement:

    assCmd = New OleDb.OleDbComm and( _
    "SELECT * from tblAssets where asset_tag=?")

    On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
    wrote:
    >Does anyone see why I'm getting this message? It errors out on line 5 at
    >"assAdapter" ?
    >Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
    >"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
    >2008\IT_Assets .mdb")
    >
    >Dim assAdapter As OleDb.OleDbData Adapter
    >
    >Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
    >asset_tag=?" )
    >
    >assCmd.Paramet ers.Add("asset_ tag", OleDbType.VarCh ar).Value = cboAsset.Text
    >
    >Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
    >
    >Dim assDT As New DataTable
    >
    >'Release the instances of the above objects
    >
    >assAdapter.Fil l(assDT)
    >
    >assAdapter.Dis pose()
    >

    Comment

    • bill

      #3
      Re: Local variable assAdapter already declared in block?

      It's still the assAdapter that errors out in this. It's not declared
      anywhere else so I just don't see why this is happening. If i take out the
      first declaration there are even more errors that come up.

      "Jack Jackson" <jjackson@cinno vations.netwrot e in message
      news:b5pa849kcq oh9e6m74c43r886 6noafne1a@4ax.c om...
      This is exactly the same problem you had in the previous example.
      >
      Either remove the first Dim (the best solution), or change the second
      one to just an assignment statement:
      >
      assCmd = New OleDb.OleDbComm and( _
      "SELECT * from tblAssets where asset_tag=?")
      >
      On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
      wrote:
      >
      >>Does anyone see why I'm getting this message? It errors out on line 5 at
      >>"assAdapter "?
      >>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
      >>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
      >>2008\IT_Asset s.mdb")
      >>
      >>Dim assAdapter As OleDb.OleDbData Adapter
      >>
      >>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
      >>asset_tag=? ")
      >>
      >>assCmd.Parame ters.Add("asset _tag", OleDbType.VarCh ar).Value =
      >>cboAsset.Te xt
      >>
      >>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
      >>
      >>Dim assDT As New DataTable
      >>
      >>'Release the instances of the above objects
      >>
      >>assAdapter.Fi ll(assDT)
      >>
      >>assAdapter.Di spose()
      >>

      Comment

      • bill

        #4
        Re: Local variable assAdapter already declared in block?

        Sorry I see where you were going with that and you are right. It works like
        this:
        assAdapter = New OleDb.OleDbData Adapter '(assCmd, Con)

        What I don't see in the properties now is how to add the command and the
        connection to the dataAdapter. Can you help me there since you've almost
        done it all now? :)

        Thank you!

        "bill"<bill@bot tlegarden.comwr ote in message
        news:OhRK3f76IH A.5012@TK2MSFTN GP02.phx.gbl...
        It's still the assAdapter that errors out in this. It's not declared
        anywhere else so I just don't see why this is happening. If i take out
        the first declaration there are even more errors that come up.
        >
        "Jack Jackson" <jjackson@cinno vations.netwrot e in message
        news:b5pa849kcq oh9e6m74c43r886 6noafne1a@4ax.c om...
        >This is exactly the same problem you had in the previous example.
        >>
        >Either remove the first Dim (the best solution), or change the second
        >one to just an assignment statement:
        >>
        > assCmd = New OleDb.OleDbComm and( _
        > "SELECT * from tblAssets where asset_tag=?")
        >>
        >On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
        >wrote:
        >>
        >>>Does anyone see why I'm getting this message? It errors out on line 5 at
        >>>"assAdapter" ?
        >>>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
        >>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
        >>>2008\IT_Asse ts.mdb")
        >>>
        >>>Dim assAdapter As OleDb.OleDbData Adapter
        >>>
        >>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
        >>>asset_tag=?" )
        >>>
        >>>assCmd.Param eters.Add("asse t_tag", OleDbType.VarCh ar).Value =
        >>>cboAsset.Tex t
        >>>
        >>>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
        >>>
        >>>Dim assDT As New DataTable
        >>>
        >>>'Release the instances of the above objects
        >>>
        >>>assAdapter.F ill(assDT)
        >>>
        >>>assAdapter.D ispose()
        >>>
        >
        >

        Comment

        • Jack Jackson

          #5
          Re: Local variable assAdapter already declared in block?

          You specify the connection in the command object.

          assCmd = New OleDb.OleDbComm and( _
          "SELECT * from tblAssets where asset_tag=?", Con)
          assAdapter = New OleDbAdapter(as sCmd)

          or
          assCmd = ...
          Dim assAdapter as New OleDbAdapter
          assAdapter.Sele ctCommand = assCmd


          On Mon, 21 Jul 2008 23:05:29 -0600, "bill" <bill@bottlegar den.com>
          wrote:
          >Sorry I see where you were going with that and you are right. It works like
          >this:
          >assAdapter = New OleDb.OleDbData Adapter '(assCmd, Con)
          >
          >What I don't see in the properties now is how to add the command and the
          >connection to the dataAdapter. Can you help me there since you've almost
          >done it all now? :)
          >
          >Thank you!
          >
          >"bill"<bill@bo ttlegarden.comw rote in message
          >news:OhRK3f76I HA.5012@TK2MSFT NGP02.phx.gbl.. .
          >It's still the assAdapter that errors out in this. It's not declared
          >anywhere else so I just don't see why this is happening. If i take out
          >the first declaration there are even more errors that come up.
          >>
          >"Jack Jackson" <jjackson@cinno vations.netwrot e in message
          >news:b5pa849kc qoh9e6m74c43r88 66noafne1a@4ax. com...
          >>This is exactly the same problem you had in the previous example.
          >>>
          >>Either remove the first Dim (the best solution), or change the second
          >>one to just an assignment statement:
          >>>
          >> assCmd = New OleDb.OleDbComm and( _
          >> "SELECT * from tblAssets where asset_tag=?")
          >>>
          >>On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
          >>wrote:
          >>>
          >>>>Does anyone see why I'm getting this message? It errors out on line 5 at
          >>>>"assAdapter "?
          >>>>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
          >>>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
          >>>>2008\IT_Ass ets.mdb")
          >>>>
          >>>>Dim assAdapter As OleDb.OleDbData Adapter
          >>>>
          >>>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
          >>>>asset_tag=? ")
          >>>>
          >>>>assCmd.Para meters.Add("ass et_tag", OleDbType.VarCh ar).Value =
          >>>>cboAsset.Te xt
          >>>>
          >>>>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
          >>>>
          >>>>Dim assDT As New DataTable
          >>>>
          >>>>'Release the instances of the above objects
          >>>>
          >>>>assAdapter. Fill(assDT)
          >>>>
          >>>>assAdapter. Dispose()
          >>>>
          >>
          >>
          >

          Comment

          • bill

            #6
            Re: Local variable assAdapter already declared in block?

            Thank you again! That got it:) Though there is more now.... I get an error
            at "assAdapter.fil l(assDT)" that says "fill: SelectCommand.C onnection
            property has not been initialized? Do you see why?
            Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
            "data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
            2008\IT_Assets. mdb")

            Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
            asset_tag=?")

            Dim assAdapter As OleDb.OleDbData Adapter

            assAdapter = New OleDb.OleDbData Adapter(assCmd)

            'Dim assCmd As OleDb.OleDbComm and

            assCmd = New OleDb.OleDbComm and("SELECT * from tblAssets where asset_tag=?",
            Con)

            assCmd.Paramete rs.Add("asset_t ag", OleDbType.VarCh ar).Value = cboAsset.Text

            Dim assDT As New DataTable

            'Need to initialize the dataAdapter here

            'Release the instances of the above objects

            assAdapter.Fill (assDT)

            'assAdapter.Dis pose()

            Me.DataGridView 1.DataSource = assDT

            End If



            "Jack Jackson" <jjackson@cinno vations.netwrot e in message
            news:f67c84lj9a 92i4ds6rk7vrbnp a0f517mn5@4ax.c om...
            You specify the connection in the command object.
            >
            assCmd = New OleDb.OleDbComm and( _
            "SELECT * from tblAssets where asset_tag=?", Con)
            assAdapter = New OleDbAdapter(as sCmd)
            >
            or
            assCmd = ...
            Dim assAdapter as New OleDbAdapter
            assAdapter.Sele ctCommand = assCmd
            >
            >
            On Mon, 21 Jul 2008 23:05:29 -0600, "bill" <bill@bottlegar den.com>
            wrote:
            >
            >>Sorry I see where you were going with that and you are right. It works
            >>like
            >>this:
            >>assAdapter = New OleDb.OleDbData Adapter '(assCmd, Con)
            >>
            >>What I don't see in the properties now is how to add the command and the
            >>connection to the dataAdapter. Can you help me there since you've almost
            >>done it all now? :)
            >>
            >>Thank you!
            >>
            >>"bill"<bill@b ottlegarden.com wrote in message
            >>news:OhRK3f76 IHA.5012@TK2MSF TNGP02.phx.gbl. ..
            >>It's still the assAdapter that errors out in this. It's not declared
            >>anywhere else so I just don't see why this is happening. If i take out
            >>the first declaration there are even more errors that come up.
            >>>
            >>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
            >>news:b5pa849k cqoh9e6m74c43r8 866noafne1a@4ax .com...
            >>>This is exactly the same problem you had in the previous example.
            >>>>
            >>>Either remove the first Dim (the best solution), or change the second
            >>>one to just an assignment statement:
            >>>>
            >>> assCmd = New OleDb.OleDbComm and( _
            >>> "SELECT * from tblAssets where asset_tag=?")
            >>>>
            >>>On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
            >>>wrote:
            >>>>
            >>>>>Does anyone see why I'm getting this message? It errors out on line 5
            >>>>>at
            >>>>>"assAdapte r"?
            >>>>>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;"
            >>>>>&
            >>>>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
            >>>>>2008\IT_As sets.mdb")
            >>>>>
            >>>>>Dim assAdapter As OleDb.OleDbData Adapter
            >>>>>
            >>>>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
            >>>>>asset_tag= ?")
            >>>>>
            >>>>>assCmd.Par ameters.Add("as set_tag", OleDbType.VarCh ar).Value =
            >>>>>cboAsset.T ext
            >>>>>
            >>>>>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
            >>>>>
            >>>>>Dim assDT As New DataTable
            >>>>>
            >>>>>'Release the instances of the above objects
            >>>>>
            >>>>>assAdapter .Fill(assDT)
            >>>>>
            >>>>>assAdapter .Dispose()
            >>>>>
            >>>
            >>>
            >>

            Comment

            • Jack Jackson

              #7
              Re: Local variable assAdapter already declared in block?

              Sure. The message says it all. The DataAdapter's Select command,
              which is built from the text you pass to the DataAdapter's
              constructor, doesn't have any connection info.

              See my comments below.
              >assCmd = New OleDb.OleDbComm and( _
              > "SELECT * from tblAssets where asset_tag=?", Con)
              >assAdapter = New OleDbAdapter(as sCmd)
              On Tue, 22 Jul 2008 18:05:09 -0600, "bill" <bill@bottlegar den.com>
              wrote:
              >Thank you again! That got it:) Though there is more now.... I get an error
              >at "assAdapter.fil l(assDT)" that says "fill: SelectCommand.C onnection
              >property has not been initialized? Do you see why?
              >Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
              >"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
              >2008\IT_Assets .mdb")
              The following line creates an OleDbCommand without a connection
              object.
              >Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
              >asset_tag=?" )
              >
              >Dim assAdapter As OleDb.OleDbData Adapter
              The following line creates a DataAdapter from the OleDbCommand object
              that doesn't have a connection object.
              >assAdapter = New OleDb.OleDbData Adapter(assCmd)
              >
              >'Dim assCmd As OleDb.OleDbComm and
              The following line creates a second command object with the same
              select as the previous one, this time with a connection object. This
              command object is never used. You should get rid of this line, and
              add Con as a second parameter to the previous OleDbCommand.
              >assCmd = New OleDb.OleDbComm and("SELECT * from tblAssets where asset_tag=?",
              >Con)
              >
              >assCmd.Paramet ers.Add("asset_ tag", OleDbType.VarCh ar).Value = cboAsset.Text
              >
              >Dim assDT As New DataTable
              >
              >'Need to initialize the dataAdapter here
              >
              >'Release the instances of the above objects
              >
              >assAdapter.Fil l(assDT)
              >
              >'assAdapter.Di spose()
              >
              >Me.DataGridVie w1.DataSource = assDT
              >
              >End If
              >
              >
              >
              >"Jack Jackson" <jjackson@cinno vations.netwrot e in message
              >news:f67c84lj9 a92i4ds6rk7vrbn pa0f517mn5@4ax. com...
              >You specify the connection in the command object.
              >>
              >assCmd = New OleDb.OleDbComm and( _
              > "SELECT * from tblAssets where asset_tag=?", Con)
              >assAdapter = New OleDbAdapter(as sCmd)
              >>
              >or
              >assCmd = ...
              >Dim assAdapter as New OleDbAdapter
              >assAdapter.Sel ectCommand = assCmd
              >>
              >>
              >On Mon, 21 Jul 2008 23:05:29 -0600, "bill" <bill@bottlegar den.com>
              >wrote:
              >>
              >>>Sorry I see where you were going with that and you are right. It works
              >>>like
              >>>this:
              >>>assAdapter = New OleDb.OleDbData Adapter '(assCmd, Con)
              >>>
              >>>What I don't see in the properties now is how to add the command and the
              >>>connection to the dataAdapter. Can you help me there since you've almost
              >>>done it all now? :)
              >>>
              >>>Thank you!
              >>>
              >>>"bill"<bill@ bottlegarden.co mwrote in message
              >>>news:OhRK3f7 6IHA.5012@TK2MS FTNGP02.phx.gbl ...
              >>>It's still the assAdapter that errors out in this. It's not declared
              >>>anywhere else so I just don't see why this is happening. If i take out
              >>>the first declaration there are even more errors that come up.
              >>>>
              >>>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
              >>>news:b5pa849 kcqoh9e6m74c43r 8866noafne1a@4a x.com...
              >>>>This is exactly the same problem you had in the previous example.
              >>>>>
              >>>>Either remove the first Dim (the best solution), or change the second
              >>>>one to just an assignment statement:
              >>>>>
              >>>> assCmd = New OleDb.OleDbComm and( _
              >>>> "SELECT * from tblAssets where asset_tag=?")
              >>>>>
              >>>>On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
              >>>>wrote:
              >>>>>
              >>>>>>Does anyone see why I'm getting this message? It errors out on line 5
              >>>>>>at
              >>>>>>"assAdapt er"?
              >>>>>>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;"
              >>>>>>&
              >>>>>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
              >>>>>>2008\IT_A ssets.mdb")
              >>>>>>
              >>>>>>Dim assAdapter As OleDb.OleDbData Adapter
              >>>>>>
              >>>>>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
              >>>>>>asset_tag =?")
              >>>>>>
              >>>>>>assCmd.Pa rameters.Add("a sset_tag", OleDbType.VarCh ar).Value =
              >>>>>>cboAsset. Text
              >>>>>>
              >>>>>>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
              >>>>>>
              >>>>>>Dim assDT As New DataTable
              >>>>>>
              >>>>>>'Releas e the instances of the above objects
              >>>>>>
              >>>>>>assAdapte r.Fill(assDT)
              >>>>>>
              >>>>>>assAdapte r.Dispose()
              >>>>>>
              >>>>
              >>>>
              >>>
              >

              Comment

              • bill

                #8
                Re: Local variable assAdapter already declared in block?

                Oh man, I should have seen that. I comment out that lin, add the con to the
                second and it works perfectly. Thank you so much! You have been incredibly
                helpful and patient and I really appreciate it. I have learned allot!
                Thank you!
                Bill Bray

                "Jack Jackson" <jjackson@cinno vations.netwrot e in message
                news:pkid841jv1 v9t9r705clrbc5b phn5u8kgr@4ax.c om...
                Sure. The message says it all. The DataAdapter's Select command,
                which is built from the text you pass to the DataAdapter's
                constructor, doesn't have any connection info.
                >
                See my comments below.
                >
                >>assCmd = New OleDb.OleDbComm and( _
                >> "SELECT * from tblAssets where asset_tag=?", Con)
                >>assAdapter = New OleDbAdapter(as sCmd)
                >
                On Tue, 22 Jul 2008 18:05:09 -0600, "bill" <bill@bottlegar den.com>
                wrote:
                >
                >>Thank you again! That got it:) Though there is more now.... I get an
                >>error
                >>at "assAdapter.fil l(assDT)" that says "fill: SelectCommand.C onnection
                >>property has not been initialized? Do you see why?
                >>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
                >>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
                >>2008\IT_Asset s.mdb")
                >
                The following line creates an OleDbCommand without a connection
                object.
                >
                >>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
                >>asset_tag=? ")
                >>
                >>Dim assAdapter As OleDb.OleDbData Adapter
                >
                The following line creates a DataAdapter from the OleDbCommand object
                that doesn't have a connection object.
                >
                >>assAdapter = New OleDb.OleDbData Adapter(assCmd)
                >>
                >>'Dim assCmd As OleDb.OleDbComm and
                >
                The following line creates a second command object with the same
                select as the previous one, this time with a connection object. This
                command object is never used. You should get rid of this line, and
                add Con as a second parameter to the previous OleDbCommand.
                >
                >>assCmd = New OleDb.OleDbComm and("SELECT * from tblAssets where
                >>asset_tag=? ",
                >>Con)
                >>
                >>assCmd.Parame ters.Add("asset _tag", OleDbType.VarCh ar).Value =
                >>cboAsset.Te xt
                >>
                >>Dim assDT As New DataTable
                >>
                >>'Need to initialize the dataAdapter here
                >>
                >>'Release the instances of the above objects
                >>
                >>assAdapter.Fi ll(assDT)
                >>
                >>'assAdapter.D ispose()
                >>
                >>Me.DataGridVi ew1.DataSource = assDT
                >>
                >>End If
                >>
                >>
                >>
                >>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                >>news:f67c84lj 9a92i4ds6rk7vrb npa0f517mn5@4ax .com...
                >>You specify the connection in the command object.
                >>>
                >>assCmd = New OleDb.OleDbComm and( _
                >> "SELECT * from tblAssets where asset_tag=?", Con)
                >>assAdapter = New OleDbAdapter(as sCmd)
                >>>
                >>or
                >>assCmd = ...
                >>Dim assAdapter as New OleDbAdapter
                >>assAdapter.Se lectCommand = assCmd
                >>>
                >>>
                >>On Mon, 21 Jul 2008 23:05:29 -0600, "bill" <bill@bottlegar den.com>
                >>wrote:
                >>>
                >>>>Sorry I see where you were going with that and you are right. It works
                >>>>like
                >>>>this:
                >>>>assAdapte r = New OleDb.OleDbData Adapter '(assCmd, Con)
                >>>>
                >>>>What I don't see in the properties now is how to add the command and the
                >>>>connectio n to the dataAdapter. Can you help me there since you've
                >>>>almost
                >>>>done it all now? :)
                >>>>
                >>>>Thank you!
                >>>>
                >>>>"bill"<bill @bottlegarden.c omwrote in message
                >>>>news:OhRK3f 76IHA.5012@TK2M SFTNGP02.phx.gb l...
                >>>>It's still the assAdapter that errors out in this. It's not declared
                >>>>anywhere else so I just don't see why this is happening. If i take
                >>>>out
                >>>>the first declaration there are even more errors that come up.
                >>>>>
                >>>>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                >>>>news:b5pa84 9kcqoh9e6m74c43 r8866noafne1a@4 ax.com...
                >>>>>This is exactly the same problem you had in the previous example.
                >>>>>>
                >>>>>Either remove the first Dim (the best solution), or change the second
                >>>>>one to just an assignment statement:
                >>>>>>
                >>>>> assCmd = New OleDb.OleDbComm and( _
                >>>>> "SELECT * from tblAssets where asset_tag=?")
                >>>>>>
                >>>>>On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
                >>>>>wrote:
                >>>>>>
                >>>>>>>Does anyone see why I'm getting this message? It errors out on line
                >>>>>>>5
                >>>>>>>at
                >>>>>>>"assAdap ter"?
                >>>>>>>Dim Con = New
                >>>>>>>OleDb.Ol eDbConnection(" provider=micros oft.jet.oledb.4 .0;"
                >>>>>>>&
                >>>>>>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
                >>>>>>>2008\IT_ Assets.mdb")
                >>>>>>>
                >>>>>>>Dim assAdapter As OleDb.OleDbData Adapter
                >>>>>>>
                >>>>>>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
                >>>>>>>asset_ta g=?")
                >>>>>>>
                >>>>>>>assCmd.P arameters.Add(" asset_tag", OleDbType.VarCh ar).Value =
                >>>>>>>cboAsset .Text
                >>>>>>>
                >>>>>>>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
                >>>>>>>
                >>>>>>>Dim assDT As New DataTable
                >>>>>>>
                >>>>>>>'Relea se the instances of the above objects
                >>>>>>>
                >>>>>>>assAdapt er.Fill(assDT)
                >>>>>>>
                >>>>>>>assAdapt er.Dispose()
                >>>>>>>
                >>>>>
                >>>>>
                >>>>
                >>

                Comment

                • sloan

                  #9
                  Re: Local variable assAdapter already declared in block?


                  Now you can work on your naming conventions.

                  The @$$Adaptor sounds like something you use to get a colonoscopy and you
                  have an oversized or undersized butt. (ha ha).

                  ...



                  "bill" <bill@bottlegar den.comwrote in message
                  news:ubas75J7IH A.4108@TK2MSFTN GP04.phx.gbl...
                  Oh man, I should have seen that. I comment out that lin, add the con to
                  the second and it works perfectly. Thank you so much! You have been
                  incredibly helpful and patient and I really appreciate it. I have learned
                  allot!
                  Thank you!
                  Bill Bray
                  >
                  "Jack Jackson" <jjackson@cinno vations.netwrot e in message
                  news:pkid841jv1 v9t9r705clrbc5b phn5u8kgr@4ax.c om...
                  >Sure. The message says it all. The DataAdapter's Select command,
                  >which is built from the text you pass to the DataAdapter's
                  >constructor, doesn't have any connection info.
                  >>
                  >See my comments below.
                  >>
                  >>>assCmd = New OleDb.OleDbComm and( _
                  >>> "SELECT * from tblAssets where asset_tag=?", Con)
                  >>>assAdapter = New OleDbAdapter(as sCmd)
                  >>
                  >On Tue, 22 Jul 2008 18:05:09 -0600, "bill" <bill@bottlegar den.com>
                  >wrote:
                  >>
                  >>>Thank you again! That got it:) Though there is more now.... I get an
                  >>>error
                  >>>at "assAdapter.fil l(assDT)" that says "fill: SelectCommand.C onnection
                  >>>property has not been initialized? Do you see why?
                  >>>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;" &
                  >>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
                  >>>2008\IT_Asse ts.mdb")
                  >>
                  >The following line creates an OleDbCommand without a connection
                  >object.
                  >>
                  >>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
                  >>>asset_tag=?" )
                  >>>
                  >>>Dim assAdapter As OleDb.OleDbData Adapter
                  >>
                  >The following line creates a DataAdapter from the OleDbCommand object
                  >that doesn't have a connection object.
                  >>
                  >>>assAdapter = New OleDb.OleDbData Adapter(assCmd)
                  >>>
                  >>>'Dim assCmd As OleDb.OleDbComm and
                  >>
                  >The following line creates a second command object with the same
                  >select as the previous one, this time with a connection object. This
                  >command object is never used. You should get rid of this line, and
                  >add Con as a second parameter to the previous OleDbCommand.
                  >>
                  >>>assCmd = New OleDb.OleDbComm and("SELECT * from tblAssets where
                  >>>asset_tag=?" ,
                  >>>Con)
                  >>>
                  >>>assCmd.Param eters.Add("asse t_tag", OleDbType.VarCh ar).Value =
                  >>>cboAsset.Tex t
                  >>>
                  >>>Dim assDT As New DataTable
                  >>>
                  >>>'Need to initialize the dataAdapter here
                  >>>
                  >>>'Release the instances of the above objects
                  >>>
                  >>>assAdapter.F ill(assDT)
                  >>>
                  >>>'assAdapter. Dispose()
                  >>>
                  >>>Me.DataGridV iew1.DataSource = assDT
                  >>>
                  >>>End If
                  >>>
                  >>>
                  >>>
                  >>>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                  >>>news:f67c84l j9a92i4ds6rk7vr bnpa0f517mn5@4a x.com...
                  >>>You specify the connection in the command object.
                  >>>>
                  >>>assCmd = New OleDb.OleDbComm and( _
                  >>> "SELECT * from tblAssets where asset_tag=?", Con)
                  >>>assAdapter = New OleDbAdapter(as sCmd)
                  >>>>
                  >>>or
                  >>>assCmd = ...
                  >>>Dim assAdapter as New OleDbAdapter
                  >>>assAdapter.S electCommand = assCmd
                  >>>>
                  >>>>
                  >>>On Mon, 21 Jul 2008 23:05:29 -0600, "bill" <bill@bottlegar den.com>
                  >>>wrote:
                  >>>>
                  >>>>>Sorry I see where you were going with that and you are right. It works
                  >>>>>like
                  >>>>>this:
                  >>>>>assAdapt er = New OleDb.OleDbData Adapter '(assCmd, Con)
                  >>>>>
                  >>>>>What I don't see in the properties now is how to add the command and
                  >>>>>the
                  >>>>>connecti on to the dataAdapter. Can you help me there since you've
                  >>>>>almost
                  >>>>>done it all now? :)
                  >>>>>
                  >>>>>Thank you!
                  >>>>>
                  >>>>>"bill"<bil l@bottlegarden. comwrote in message
                  >>>>>news:OhRK3 f76IHA.5012@TK2 MSFTNGP02.phx.g bl...
                  >>>>>It's still the assAdapter that errors out in this. It's not declared
                  >>>>>anywhere else so I just don't see why this is happening. If i take
                  >>>>>out
                  >>>>>the first declaration there are even more errors that come up.
                  >>>>>>
                  >>>>>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                  >>>>>news:b5pa8 49kcqoh9e6m74c4 3r8866noafne1a@ 4ax.com...
                  >>>>>>This is exactly the same problem you had in the previous example.
                  >>>>>>>
                  >>>>>>Either remove the first Dim (the best solution), or change the
                  >>>>>>second
                  >>>>>>one to just an assignment statement:
                  >>>>>>>
                  >>>>>> assCmd = New OleDb.OleDbComm and( _
                  >>>>>> "SELECT * from tblAssets where asset_tag=?")
                  >>>>>>>
                  >>>>>>On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
                  >>>>>>wrote:
                  >>>>>>>
                  >>>>>>>>Does anyone see why I'm getting this message? It errors out on line
                  >>>>>>>>5
                  >>>>>>>>at
                  >>>>>>>>"assAda pter"?
                  >>>>>>>>Dim Con = New
                  >>>>>>>>OleDb.O leDbConnection( "provider=micro soft.jet.oledb. 4.0;"
                  >>>>>>>>&
                  >>>>>>>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re
                  >>>>>>>>Trackin g -
                  >>>>>>>>2008\IT _Assets.mdb")
                  >>>>>>>>
                  >>>>>>>>Dim assAdapter As OleDb.OleDbData Adapter
                  >>>>>>>>
                  >>>>>>>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
                  >>>>>>>>asset_t ag=?")
                  >>>>>>>>
                  >>>>>>>>assCmd. Parameters.Add( "asset_tag" , OleDbType.VarCh ar).Value =
                  >>>>>>>>cboAsse t.Text
                  >>>>>>>>
                  >>>>>>>>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
                  >>>>>>>>
                  >>>>>>>>Dim assDT As New DataTable
                  >>>>>>>>
                  >>>>>>>>'Releas e the instances of the above objects
                  >>>>>>>>
                  >>>>>>>>assAdap ter.Fill(assDT)
                  >>>>>>>>
                  >>>>>>>>assAdap ter.Dispose()
                  >>>>>>>>
                  >>>>>>
                  >>>>>>
                  >>>>>
                  >>>
                  >
                  >

                  Comment

                  • bill

                    #10
                    Re: Local variable assAdapter already declared in block?

                    LOL! I thought someone would have said something sooner:)

                    It just made sense to me...it was a data adapter for the assets....but it
                    still made me chuckle.

                    "sloan" <sloan@ipass.ne twrote in message
                    news:OOntyqZ7IH A.2416@TK2MSFTN GP02.phx.gbl...
                    >
                    Now you can work on your naming conventions.
                    >
                    The @$$Adaptor sounds like something you use to get a colonoscopy and you
                    have an oversized or undersized butt. (ha ha).
                    >
                    ..
                    >
                    >
                    >
                    "bill" <bill@bottlegar den.comwrote in message
                    news:ubas75J7IH A.4108@TK2MSFTN GP04.phx.gbl...
                    >Oh man, I should have seen that. I comment out that lin, add the con to
                    >the second and it works perfectly. Thank you so much! You have been
                    >incredibly helpful and patient and I really appreciate it. I have
                    >learned allot!
                    >Thank you!
                    >Bill Bray
                    >>
                    >"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                    >news:pkid841jv 1v9t9r705clrbc5 bphn5u8kgr@4ax. com...
                    >>Sure. The message says it all. The DataAdapter's Select command,
                    >>which is built from the text you pass to the DataAdapter's
                    >>constructor , doesn't have any connection info.
                    >>>
                    >>See my comments below.
                    >>>
                    >>>>assCmd = New OleDb.OleDbComm and( _
                    >>>> "SELECT * from tblAssets where asset_tag=?", Con)
                    >>>>assAdapte r = New OleDbAdapter(as sCmd)
                    >>>
                    >>On Tue, 22 Jul 2008 18:05:09 -0600, "bill" <bill@bottlegar den.com>
                    >>wrote:
                    >>>
                    >>>>Thank you again! That got it:) Though there is more now.... I get an
                    >>>>error
                    >>>>at "assAdapter.fil l(assDT)" that says "fill: SelectCommand.C onnection
                    >>>>property has not been initialized? Do you see why?
                    >>>>Dim Con = New OleDb.OleDbConn ection("provide r=microsoft.jet .oledb.4.0;"
                    >>>>&
                    >>>>"data source=c:\_Arch ive\Documentati on - Projects\Hardwa re Tracking -
                    >>>>2008\IT_Ass ets.mdb")
                    >>>
                    >>The following line creates an OleDbCommand without a connection
                    >>object.
                    >>>
                    >>>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
                    >>>>asset_tag=? ")
                    >>>>
                    >>>>Dim assAdapter As OleDb.OleDbData Adapter
                    >>>
                    >>The following line creates a DataAdapter from the OleDbCommand object
                    >>that doesn't have a connection object.
                    >>>
                    >>>>assAdapte r = New OleDb.OleDbData Adapter(assCmd)
                    >>>>
                    >>>>'Dim assCmd As OleDb.OleDbComm and
                    >>>
                    >>The following line creates a second command object with the same
                    >>select as the previous one, this time with a connection object. This
                    >>command object is never used. You should get rid of this line, and
                    >>add Con as a second parameter to the previous OleDbCommand.
                    >>>
                    >>>>assCmd = New OleDb.OleDbComm and("SELECT * from tblAssets where
                    >>>>asset_tag=? ",
                    >>>>Con)
                    >>>>
                    >>>>assCmd.Para meters.Add("ass et_tag", OleDbType.VarCh ar).Value =
                    >>>>cboAsset.Te xt
                    >>>>
                    >>>>Dim assDT As New DataTable
                    >>>>
                    >>>>'Need to initialize the dataAdapter here
                    >>>>
                    >>>>'Release the instances of the above objects
                    >>>>
                    >>>>assAdapter. Fill(assDT)
                    >>>>
                    >>>>'assAdapter .Dispose()
                    >>>>
                    >>>>Me.DataGrid View1.DataSourc e = assDT
                    >>>>
                    >>>>End If
                    >>>>
                    >>>>
                    >>>>
                    >>>>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                    >>>>news:f67c84 lj9a92i4ds6rk7v rbnpa0f517mn5@4 ax.com...
                    >>>>You specify the connection in the command object.
                    >>>>>
                    >>>>assCmd = New OleDb.OleDbComm and( _
                    >>>> "SELECT * from tblAssets where asset_tag=?", Con)
                    >>>>assAdapte r = New OleDbAdapter(as sCmd)
                    >>>>>
                    >>>>or
                    >>>>assCmd = ...
                    >>>>Dim assAdapter as New OleDbAdapter
                    >>>>assAdapter. SelectCommand = assCmd
                    >>>>>
                    >>>>>
                    >>>>On Mon, 21 Jul 2008 23:05:29 -0600, "bill" <bill@bottlegar den.com>
                    >>>>wrote:
                    >>>>>
                    >>>>>>Sorry I see where you were going with that and you are right. It
                    >>>>>>works
                    >>>>>>like
                    >>>>>>this:
                    >>>>>>assAdapte r = New OleDb.OleDbData Adapter '(assCmd, Con)
                    >>>>>>
                    >>>>>>What I don't see in the properties now is how to add the command and
                    >>>>>>the
                    >>>>>>connectio n to the dataAdapter. Can you help me there since you've
                    >>>>>>almost
                    >>>>>>done it all now? :)
                    >>>>>>
                    >>>>>>Thank you!
                    >>>>>>
                    >>>>>>"bill"<bi ll@bottlegarden .comwrote in message
                    >>>>>>news:OhRK 3f76IHA.5012@TK 2MSFTNGP02.phx. gbl...
                    >>>>>>It's still the assAdapter that errors out in this. It's not
                    >>>>>>declare d
                    >>>>>>anywher e else so I just don't see why this is happening. If i take
                    >>>>>>out
                    >>>>>>the first declaration there are even more errors that come up.
                    >>>>>>>
                    >>>>>>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                    >>>>>>news:b5pa 849kcqoh9e6m74c 43r8866noafne1a @4ax.com...
                    >>>>>>>This is exactly the same problem you had in the previous example.
                    >>>>>>>>
                    >>>>>>>Either remove the first Dim (the best solution), or change the
                    >>>>>>>second
                    >>>>>>>one to just an assignment statement:
                    >>>>>>>>
                    >>>>>>> assCmd = New OleDb.OleDbComm and( _
                    >>>>>>> "SELECT * from tblAssets where asset_tag=?")
                    >>>>>>>>
                    >>>>>>>On Mon, 21 Jul 2008 22:24:14 -0600, "bill" <bill@bottlegar den.com>
                    >>>>>>>wrote:
                    >>>>>>>>
                    >>>>>>>>>Does anyone see why I'm getting this message? It errors out on
                    >>>>>>>>>line 5
                    >>>>>>>>>at
                    >>>>>>>>>"assAd apter"?
                    >>>>>>>>>Dim Con = New
                    >>>>>>>>>OleDb. OleDbConnection ("provider=micr osoft.jet.oledb .4.0;"
                    >>>>>>>>>&
                    >>>>>>>>>"dat a source=c:\_Arch ive\Documentati on - Projects\Hardwa re
                    >>>>>>>>>Tracki ng -
                    >>>>>>>>>2008\I T_Assets.mdb")
                    >>>>>>>>>
                    >>>>>>>>>Dim assAdapter As OleDb.OleDbData Adapter
                    >>>>>>>>>
                    >>>>>>>>>Dim assCmd As New OleDb.OleDbComm and("SELECT * from tblAssets where
                    >>>>>>>>>asset_ tag=?")
                    >>>>>>>>>
                    >>>>>>>>>assCmd .Parameters.Add ("asset_tag" , OleDbType.VarCh ar).Value =
                    >>>>>>>>>cboAss et.Text
                    >>>>>>>>>
                    >>>>>>>>>Dim assAdapter As New OleDb.OleDbData Adapter(assCmd, Con)
                    >>>>>>>>>
                    >>>>>>>>>Dim assDT As New DataTable
                    >>>>>>>>>
                    >>>>>>>>>'Relea se the instances of the above objects
                    >>>>>>>>>
                    >>>>>>>>>assAda pter.Fill(assDT )
                    >>>>>>>>>
                    >>>>>>>>>assAda pter.Dispose()
                    >>>>>>>>>
                    >>>>>>>
                    >>>>>>>
                    >>>>>>
                    >>>>
                    >>
                    >>
                    >
                    >

                    Comment

                    Working...