Cant add paramenter to data adapter

Posted on 2014-03-19
Medium Priority
Last Modified: 2014-03-19
I have a data adapter I am trying to associate parameters to so I can run an da.update(ds) statement.  Here is my code.

Dim myCMD As New SqlCommand
        myCMD.Connection = myConn
        myCMD.CommandText = "TAG_UpdateSQFT"
        myCMD.CommandType = CommandType.StoredProcedure
        Dim param1 As New SqlParameter("@SQFT", SqlDbType.NVarChar, 10, "SQFT")
        Dim param2 As New SqlParameter("@ID", SqlDbType.Int, 10, "ID")
        myDA.UpdateCommand.Parameters.Add(New SqlParameter(param1))
        myDA.UpdateCommand = myCMD

Open in new window

Keeps dealing me I need the new keyword.  Could someone help me out.

thanks in advance.
Question by:mgmhicks
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 52

Accepted Solution

Carl Tawn earned 2000 total points
ID: 39939890
You need to switch these lines:
        myDA.UpdateCommand.Parameters.Add(New SqlParameter(param1))
        myDA.UpdateCommand = myCMD

Open in new window

        myDA.UpdateCommand = myCMD
        myDA.UpdateCommand.Parameters.Add(New SqlParameter(param1))

Open in new window

As you need to assign a command object to the UpdateCommand before you can start altering it.
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39939908
Or change the "myDA.UpdateCommand" in lines 7 and 8 to "myCMD".

Author Closing Comment

ID: 39940650
thank you

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question