|
-
March 5th, 2010, 08:56 PM
#1
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);
-
March 5th, 2010, 09:55 PM
#2
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.
-
March 5th, 2010, 10:53 PM
#3
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.
-
March 5th, 2010, 11:10 PM
#4
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.
-
March 6th, 2010, 08:21 AM
#5
Re: Help calling an object, new to OOP and know I am missing something stupid.
 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: }
-
March 6th, 2010, 10:30 AM
#6
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.
-
March 6th, 2010, 10:47 AM
#7
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.
-
March 6th, 2010, 11:23 AM
#8
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!
-
March 7th, 2010, 03:01 AM
#9
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
-
March 7th, 2010, 09:24 AM
#10
Re: Help calling an object, new to OOP and know I am missing something stupid.
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|