Solved

Cant add paramenter to data adapter

Posted on 2014-03-19
3
141 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 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