Solved

Cant add paramenter to data adapter

Posted on 2014-03-19
3
140 Views
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.Parameters.Add(param2)
        myDA.UpdateCommand = myCMD

Open in new window


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

thanks in advance.
0
Comment
Question by:mgmhicks
[X]
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
3 Comments
 
LVL 52

Accepted Solution

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

Open in new window

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

Open in new window

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

Expert Comment

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

Author Closing Comment

by:mgmhicks
ID: 39940650
thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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