DataPortal.Fetch failed (Invalid operation - fetch not allowed)

DataPortal.Fetch failed (Invalid operation - fetch not allowed)

Old forum URL: forums.lhotka.net/forums/t/4332.aspx


Compiler posted on Tuesday, February 12, 2008

Hi everyone. I am having difficulty solving this problem.

Here is part of the CSLS class

 

public static Users GetUsers(string user_id)

{

return DataPortal.Fetch<Users>(new Criteria(user_id));

}

public static Users GetUsers(String User_id, String CompanyID)

{

return DataPortal.Fetch<Users>(new Criteriam(User_id, CompanyID));

}

 

 

[Serializable()]

private class Criteria

{

private string _user_id;

public string User_id

{

get { return _user_id; }

}

public Criteria(string user_id)

{

_user_id = user_id;

}

}

[Serializable()]

private class Criteriam

{

private string _userID;

private string _companyCode;

public string UserID

{

get { return _userID; }

}

public string CompanyID

{

get { return _companyCode; }

}

public Criteriam(string UserID, string CompanyID)

{

_companyCode = CompanyID;

_userID = UserID;

}

}

 

 

private void Dataportal_Fetch(Criteriam criteria)

{

using (SqlConnection cn = new SqlConnection("Data Source=JSI-MSS;Initial Catalog=GEAS;User ID=sa; password=sa04eric;Asynchronous Processing=true"))

{

cn.Open();

using (SqlCommand cm = cn.CreateCommand())

{

cm.CommandType = CommandType.StoredProcedure;

cm.CommandText = "sp_user_PSWExpired";

cm.Parameters.AddWithValue("@User_id", criteria.UserID);

cm.Parameters.AddWithValue("@company_code", criteria.CompanyID);

cm.Parameters.Add("@Expired", SqlDbType.Bit).Value = false;

cm.Parameters["@Expired"].Direction = ParameterDirection.InputOutput;

cm.ExecuteNonQuery();

_GetPSWExpiration = (Boolean)cm.Parameters["@Expired"].Value;

}

}

}

private void DataPortal_Fetch(Criteria criteria)

{

using (SqlConnection cn = new SqlConnection("Data Source=JSI-MSS;Initial Catalog=GEAS;User ID=sa; password=sa04eric;Asynchronous Processing=true"))

{

cn.Open();

using (SqlCommand cm = cn.CreateCommand())

{

cm.CommandType = CommandType.StoredProcedure;

cm.CommandText = "sp_user_list";

cm.Parameters.AddWithValue("@user_id", criteria.User_id);

using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))

{

dr.Read();

_user_uid = dr.GetInt32("user_uid");

_user_id = dr.GetString("user_id");

_password = dr.GetString("password");

_initials = dr.GetString("initials");

_first_name = dr.GetString("first_name");

_middle_name = dr.GetString("middle_name");

_last_name = dr.GetString("last_name");

_title = dr.GetString("title");

_suffix = dr.GetString("suffix");

_street_1 = dr.GetString("street_1");

_street_2 = dr.GetString("street_2");

_city = dr.GetString("city");

_state = dr.GetString("state");

_zip = dr.GetString("zip");

_home_phone = dr.GetString("home_phone");

_work_phone = dr.GetString("work_phone");

_mobile_phone = dr.GetString("mobile_phone");

_fax = dr.GetString("fax");

_email_addr = dr.GetString("email_addr");

_sms_addr = dr.GetString("sms_addr");

_ssn = dr.GetString("ssn");

_dln = dr.GetString("dln");

_role_uid = dr.GetInt32("role_uid");

_status = dr.GetBoolean("status");

// load child objects

dr.NextResult();

}

}

}

}

 

 

I have 2 GetUsers static procedure. The other one has 2 parameters while the other one has only one.

public static Users GetUsers(string user_id)

public static Users GetUsers(String User_id, String CompanyID)

 

The first GetUsers call the Dataportal_fetch

private void DataPortal_Fetch(Criteria criteria)

 

while the second one calls the Dataportal_fetch which has different parameter than the first one.

private void Dataportal_Fetch(Criteriam criteria)

 

JoeFallon1 replied on Tuesday, February 12, 2008

You are calling the Base method in CSLA.

Try Overriding (or Overloading) the DP_Fetch method so it will call the one in your class.

Joe

 

JonnyBee replied on Wednesday, February 13, 2008

You may overload the DataPortal_Fetch method but you must use correcty casing in method name.

Dataportal_Fetch and
DataPortal_Fetch          are considered 2 different methods.

/jonny

Compiler replied on Wednesday, February 13, 2008

thanks everyone for your help.

Copyright (c) Marimer LLC