Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:52:51+00:00 2026-06-14T05:52:51+00:00

Hey all I’ve been trying to find some resources on how to go about

  • 0

Hey all I’ve been trying to find some resources on how to go about doing this but am unable to find anything since, really, i do not know really what it would be called in the first place.

The code in question is this:

Dim updateCmd As New SqlCommand(sql, myCONN)

There are a few places that i need to use that over that’s inside an IF THEN structure.

However, when i dim it outside the IF THEN structure then it tells me (inside the IF THEN) that its not declared.

So the full example is this:

If alreadyCreatedSettingsTable = False Then
   Dim updateCmd As New SqlCommand(sql, myCONN)

   updateCmd.Parameters.Add("@urlLink", SqlDbType.VarChar)
End If

rssItems = rssDoc.SelectNodes("rss/channel/item")

For i = 0 To rssItems.Count - 1
   rssDetail = rssItems.Item(i).SelectSingleNode("link")

   If rssDetail.Equals(Nothing) = False Then
      rssLink = rssDetail.InnerText.Trim
      updateCmd.Parameters("@urlLink").Value = rssLink
   End If
etc....

The If alreadyCreatedSettingsTable = False Then dim works just fine for the updateCmd.Parameters.Add but when its inside the For i = 0 To rssItems.Count – 1 that is where it tells me its not decalired.

How can i use that anywhere no matter what and reDim it?

I’ve tried

Dim updateCmd

But i then do not know how to set As New SqlCommand(sql, myCONN) since its already been Dim’ed already?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:52:52+00:00Added an answer on June 14, 2026 at 5:52 am

    Dim declares a variable. As New is just syntactic sugar; the scope of the variable is inside that If block. Declare it outside and initialize it inside:

    Dim updateCmd As SqlCommand
    
    If alreadyCreatedSettingsTable = False Then
       sql = "UPDATE jotSettings " & _
                            "etc etc...."
    
       updateCmd = New SqlCommand(sql, myCONN)
    
       updateCmd.Parameters.Add("@urlLink", SqlDbType.VarChar)
    End If
    
    rssItems = rssDoc.SelectNodes("rss/channel/item")
    
    For i = 0 To rssItems.Count - 1
       rssDetail = rssItems.Item(i).SelectSingleNode("link")
    
       If rssDetail.Equals(Nothing) = False Then
          rssLink = rssDetail.InnerText.Trim
          updateCmd.Parameters("@urlLink").Value = rssLink
       End If
    

    Also, please never write = False; use Not instead. Or, in the case of rssDetail.Equals(Nothing) = False, you almost certainly want rssDetail IsNot Nothing instead.

    Finally, as written, this is pointless. If alreadyCreatedSettingsTable is True, you’ll get a NullReferenceException when you use updateCmd.Parameters("@urlLink"). It seems to me that it’s something that should be declared outside of a loop, or at class level – though that’s just a guess.

    P.S. Why are you overwriting updateCmd.Parameters("@urlLink") every time? That’s wasteful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all. I've been been trying to figure this out for a while now.
Hey all i am trying to find some code that would allow me to
Hey all i have a JSFiddle that i have been working on with trying
Hey all i am trying to figure out what i am doing incorrectly here.
Hey all i am probably overthinking this but how can i check the textbox
Hey all. Ive got a headache trying to get my head around this. I
Hey all, I don't know how to properly phrase this but when I run
Hey all i am trying to delete a key from the registery but i
Hey all- I have looked this up on here and Google but none of
Hey all i am in need of some help with this code in order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.