Click to See Complete Forum and Search --> : Help calling an object, new to OOP and know I am missing something stupid.


Eagle_f90
March 5th, 2010, 07:56 PM
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:

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:
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
SQLHelper.ExecSQLNonQuery(SQLStatment, Project, null);

mariocatch
March 5th, 2010, 08:55 PM
ExecSQLNonQuery takes 3 arguments but you're calling it with zero parameters in your foreach.

Eagle_f90
March 5th, 2010, 09:53 PM
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.

mariocatch
March 5th, 2010, 10:10 PM
well what you tried will work. what line is the error on. callstack please.

Eagle_f90
March 6th, 2010, 07:21 AM
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: }

TheGreatCthulhu
March 6th, 2010, 09:30 AM
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.

mariocatch
March 6th, 2010, 09:47 AM
The sql helper class is either not compiled or you're not showing us something because everything looks right.

Eagle_f90
March 6th, 2010, 10:23 AM
Doing a reupload fixed it. Not sure why but it did, maybe courpted upload. Thanks for helping out!

Machta
March 7th, 2010, 02:01 AM
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 :)

Eagle_f90
March 7th, 2010, 08:24 AM
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.