CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2010
    Posts
    36

    Help calling an object, new to OOP and know I am missing something stupid.

    Once again I am calling on those more experianced then me for help. Here is the situration. I have an class called "SQLHelper" which contains the objects to make calls to the SQL Server (thanks to another on here for that). I am trying to pass 3 paramiters to one of the objects but keep getting the erro "No overload for method ExecSQLNonQeruy takes X arguments". Can someone look at it and tell me what is wrong? Thanks.

    SQLHelper Code:

    Code:
    public static int ExecSQLNonQuery(string SQLQuery, string SingleParam, Array Params)
        {
            int RetVal = 0;
    
            using (SqlConnection Con = GetCon())
            {
                SqlCommand cmd = new SqlCommand();
                Con.Open();
                {
                    cmd.CommandText = SQLQuery;
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = Con;
    
                    if (SingleParam == null)
                    {
                        cmd.Parameters.Add(SingleParam);
                    }
                    else
                    {
                        foreach (SqlParameter Param in Params)
                        {
                            cmd.Parameters.Add(Param)
                        }
                    }
    
                    RetVal = cmd.ExecuteNonQuery();
                }
            }
            return RetVal;
        }
    Calling code:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Assignments_add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                const string SQLStatment = "Insert into TaskList (Task, Status) values ('@Task', 'ToBeWorked')";
                string[] Projects = txtProjects.Value.Split(';');
    
                foreach (string Project in Projects)
               {
                   SQLHelper.ExecSQLNonQuery();
                }
            }
        }
    }
    I have also tried
    Code:
    SQLHelper.ExecSQLNonQuery(SQLStatment, Project, null);

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    ExecSQLNonQuery takes 3 arguments but you're calling it with zero parameters in your foreach.

  3. #3
    Join Date
    Feb 2010
    Posts
    36

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    Right but if you look I stated I also tried calling it with:

    SQLHelper.ExecSQLNonQuery(SQLStatment, Project, null);

    which has 3 arguments but I get the same error.

  4. #4
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    well what you tried will work. what line is the error on. callstack please.

  5. #5
    Join Date
    Feb 2010
    Posts
    36

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    Quote Originally Posted by mariocatch View Post
    well what you tried will work. what line is the error on. callstack please.
    When I have the line of code with 3 arguments in it I get this:

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1501: No overload for method 'ExecSQLNonQuery' takes '3' arguments

    Source Error:



    Line 16: foreach (string Project in Projects)
    Line 17: {
    Line 18: SQLHelper.ExecSQLNonQuery(SQLStatment, Project, null);
    Line 19: }
    Line 20: }

  6. #6
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    Have you recently changed the method's signature?
    Try to recompile the whole project/solution. There should be a button or a menu entry named "Rebuild Solution" or "Rebuild ProjectName" or something like that. Could be that the compiler is not aware of some code alterations you made.
    Last edited by TheGreatCthulhu; March 6th, 2010 at 10:32 AM.

  7. #7
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    The sql helper class is either not compiled or you're not showing us something because everything looks right.

  8. #8
    Join Date
    Feb 2010
    Posts
    36

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    Doing a reupload fixed it. Not sure why but it did, maybe courpted upload. Thanks for helping out!

  9. #9
    Join Date
    Mar 2010
    Posts
    2

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    You should always rebuild your solution after correcting an error in your code that occur during VS build process in order to avoid such minor problems.

    PS: Interesting how long did it take you guys to solve it

  10. #10
    Join Date
    Feb 2010
    Posts
    36

    Re: Help calling an object, new to OOP and know I am missing something stupid.

    Quote Originally Posted by Machta View Post
    You should always rebuild your solution after correcting an error in your code that occur during VS build process in order to avoid such minor problems.

    PS: Interesting how long did it take you guys to solve it
    The hole site is in development so I am actualy not building the project but just uploading the raw files. Once the major work on the site is compleated I will build the project and upload.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured