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);
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.
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.
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.
Re: Help calling an object, new to OOP and know I am missing something stupid.
Quote:
Originally Posted by
mariocatch
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: }
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.
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.
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!
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 :)
Re: Help calling an object, new to OOP and know I am missing something stupid.
Quote:
Originally Posted by
Machta
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.