Solved

Name 'ExecuteNonQuery' is not declared error when doing insert

Posted on 2004-11-01
331 Views
Last Modified: 2006-11-17
I am trying to insert  data into a new row in a sql database.  I can get this to work in an access database but when I convert everything over to the sql I get the following error

Name 'ExecuteNonQuery' is not declared

Below is the code I am using.
All variables are definced prior to running the insert command.

Thanks for your help

Me.SqlInsertCommand1.CommandText = "INSERT INTO callcenter_outbound_timer(campaign, starttime, endtime, phone_number," & _
        " agent, notes, id) VALUES (@campaign, @starttime, @endtime, @phone_number, @agen" & _
        "t, @notes, @id); SELECT campaign, starttime, endtime, phone_number, agent, notes" & _
        ", id FROM callcenter_outbound_timer WHERE (id = @id)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@campaign", System.Data.SqlDbType.VarChar, 50, "campaign"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@starttime", System.Data.SqlDbType.DateTime, 8, "starttime"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@endtime", System.Data.SqlDbType.DateTime, 8, "endtime"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@phone_number", System.Data.SqlDbType.VarChar, 15, "phone_number"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@agent", System.Data.SqlDbType.VarChar, 20, "agent"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@notes", System.Data.SqlDbType.NVarChar, 500, "notes"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.UniqueIdentifier, 16, "id"))



 SqlConnection1.Open()
        SqlInsertCommand1.Parameters("@agent").Value = agent
        SqlInsertCommand1.Parameters("@campaign").Value = campaign
        SqlInsertCommand1.Parameters("@starttime").Value = starttime
        SqlInsertCommand1.Parameters("@endtime").Value = endtime
        SqlInsertCommand1.Parameters("@phone_number").Value = number
        SqlInsertCommand1.Parameters("@notes").Value = notes
        SqlInsertCommand1.ExecuteNonQuery()
        SqlConnection1.Close()



Thanks again

Danny
0
Question by:dnickelssa
    5 Comments
     
    LVL 10

    Expert Comment

    by:heintalus
    Have you got

    Imports System.Data.SqlClient

    at the top of your class ?
    0
     

    Author Comment

    by:dnickelssa
    Yes I do have that at the top of my page.

    Danny
    0
     
    LVL 4

    Accepted Solution

    by:
    Hi Danny,
    Did you try to run directly in SQL Server ?
    One thing, I see that your query seems not available for ExecuteNonQuery function, after insert record you select something.
    Nice day
    0
     
    LVL 10

    Expert Comment

    by:heintalus
    What is SqlInsertCommand1 declared as ?
    0
     

    Author Comment

    by:dnickelssa
    It was the select after the insert statement.  That is what I get  for letting the wizard do it for me.  I think that will be enough of that.

    Thanks for you help vin

    Danny
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now