Unable to cast object of type 'WIM2008_Web.App_Code.wim.security.data.User' to type 'WIM2008_Web.App_Code.wim.security.data.User'

I don't know if i post this in the rigth forum but it is related to database call.

this is my code:

public DataSet CustomerDetails_Select(Int32 ID)
    {
      DataSet ds = new DataSet();
      WIMConnect wimcon = new WIMConnect();
      WIMConnection cnnwim = new WIMConnection();
      ConvertDataReaderToDataTable DrToDs = new ConvertDataReaderToDataTable();
      GridViewHeadersDao gvh = new GridViewHeadersDao();
     
      try
      {
        User user = (User)HttpContext.Current.Session["user"];
        String Coid = HttpContext.Current.Session["user_COID"].ToString();
        String UserId = HttpContext.Current.Session["user_ID"].ToString();
        String DepartmentId = HttpContext.Current.Session["session_DepartmentId"].ToString();

        cnnwim = wimcon.MakeConnection();

        DataTable dtgvh = gvh.getGridViewHeaders("p_v_customer");
        Int32 rowcnt = dtgvh.Rows.Count;
        SqlCommand sqlcmd = new SqlCommand();
        sqlcmd.Connection = cnnwim.dbcon;
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.CommandText = "p_v_customer";
        sqlcmd.Parameters.Add(new SqlParameter("@UID", System.Data.SqlDbType.Int));
        sqlcmd.Parameters["@UID"].Value = UserId;
        sqlcmd.Parameters.Add(new SqlParameter("@COID", System.Data.SqlDbType.Int));
        sqlcmd.Parameters["@COID"].Value = Coid;
        sqlcmd.Parameters.Add(new SqlParameter("@CUSTID", System.Data.SqlDbType.Int));
        sqlcmd.Parameters["@CUSTID"].Value = ID.ToString();
        sqlcmd.Connection.Open();
        SqlDataReader dr = sqlcmd.ExecuteReader();
        DataTable dtData = DrToDs.getDataTable(dr);

        dtData.TableName = "data";
        ds.Tables.Add(dtData);
        ds.Tables.Add(dtgvh);
        sqlcmd.Connection.Close();
        cnnwim.dbcon.Close();
        _status = "success";

        if (dtData.Rows.Count == 0)
        {
          _errmsg = "No Data found!";
          _status = "empty";
        }
      }
      catch (Exception e)
      {
        _errmsg = e.Message;
        _status = "error";
      }
      return ds;
    }

 

The user class:

  [Serializable()]
  public class User
  {
    private String _password;
    private Int32 _id;
    private Int32 _CoId;
    private String _langu;
    private Int32 _departmentid;
    private String _departmentdescr;

    public String UserName { get; set; }
   
    public String UserFullName { get; set; }

    public String Password
    {
      get { return _password; }
      set { _password = value; }
    }

    public Int32 ID
    {
      get { return _id; }
      set { _id = value; }
    }

    public Int32 CoId
    {
      get { return _CoId; }
      set { _CoId = value; }
    }

    public String Langu
    {
      get { return _langu; }
      set { _langu = value; }
    }

    public Int32 DepartmentId
    {
      get { return _departmentid; }
      set { _departmentid = value; }
    }

    public String DepartmentDescr
    {
      get { return _departmentdescr; }
      set { _departmentdescr = value; }

    }

    public String ProviderUserKey { get; set; }

    public Boolean IsOnline { get; set; }

    public Boolean IsLockedOut { get; set; }

    public Boolean IsApproved { get; set; }

    public String PasswordQuestion { get; set; }

    public String Email { get; set; }

    public DateTime CreationDate { get; set; }

    public String Comment { get; set; }
   
  }

when i call CustomerDetails_Select from within a codebehind or other class there is no problem in this call. everyhting went ok.

But when i call the CustomerDetails_Select from an objectDataSource i get the error messoge as mentioned in the subject.

Anyone any idea what is wrong here.

To me the user class looks just like any ordinary serializable class to me. No fancy controls in the class...

 Regards

Frank de Pijper

 

 

0
fdepijper
1/17/2009 7:43:17 PM
asp.net.object-datasource 16182 articles. 0 followers. Follow

4 Replies
1053 Views

Similar Articles

[PageSpeed] 24

Hi fdepijper@ziggo.nl,

When you call it within a source code(not inherit from a Page class), it doesn't contain a user class, and therefore, it could success. However, when you call it within a page(Page contains a User object), it'll be mixed up with the built-in User object. All I suggest is to change the class name instead of user.

Thanks.


David Qian
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Wencui
1/20/2009 5:36:23 AM

Well i did as you suggested and changed the class to wimuser
So i tried to call the WimUser class instead of the User class.
Still got the same error message but now of course on WIM2008_Web.App_Code.wim.security.data.WimUser

WimUser wimuser = (WimUser)HttpContext.Current.Session["wimuser"];

And i don't know why

Oh i don't call it within a page.
As soon as the user logs in the Session wimuser gets stored as a serialized WimUser object.
Later when i make a call to other classes (dao classes) the Session object get's called from within that class..

Example

public DataTable getRequestSamples(Int32 RequestID, String SearchString)

{

DataTable dt = new DataTable();

try

{

WimUser wimuser = (WimUser)HttpContext.Current.Session["wimuser"];
SqlDataAdapter da = new SqlDataAdapter("exec p_l_requestsamples @UID=" + wimuser.ID.ToString() + ", @CoId=" + CoId + ", @REQUEST_ID=" + RequestID.ToString() + ", @SearchString ='" + SearchString + "'", wimcon.MakeConnection().dbcon);

 

 

......etc

Thanks

0
fdepijper
1/22/2009 1:35:35 PM

Thanks for your feedback fdepijper@ziggo.nl.

Since there's some problem when you convert the session value to a WimUser object, I guess you need to check the value stored in the session. Currently, we can't figure out the exact problem since we didn't know the code for storing. Please check it first, and if there's any problem, provide us more details.


David Qian
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Wencui
1/23/2009 3:30:30 AM


In my logon.aspx codebehind i call the logonuser and store the result in wimuser.

logon.aspx.cs

protected void WimLabLogin_LoggedIn(object sender, EventArgs e)

{

Session.Remove("wimuser");

UserLogon ul = new UserLogon();

WimUser wimuser = ul.LogonUser(WimLabLogin.UserName, WimLabLogin.Password);

Session.Add("wimuser", wimuser);

Session.Add("user_ID", wimuser.ID);

Session.Add("user_COID", wimuser.CoId);

Session.Add("session_langu", System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);

Session.Add("session_DepartmentId",wimuser.DepartmentId);


if (ul.LogonStatus == "success")

{ Response.Redirect("main.aspx"); }

}

 

UserLogon.cs

in the UserLogon-> LogonUser class i declare the wimuser object.

namespace WIM2008_Web.App_Code.wim.security.bm

{

public class UserLogon

{

private String _errmsg;

private String _logonstatus;

public String ErrMsg

{

get { return _errmsg; }

set { _errmsg = value; }

}

public String LogonStatus

{

get { return _logonstatus; }

set { _logonstatus = value; }

}

public WimUser LogonUser(String UserName, String Password)

{

WimUser LogonUser = new WimUser();

WIMUserConnect wimcon = new WIMUserConnect();

WIMUserConnection cnnwim = new WIMUserConnection();

DataSet ds = new DataSet();

try

{

cnnwim = wimcon.MakeConnection();

SqlDataAdapter dbadapter = new SqlDataAdapter("exec p_x_getuserinfo @USER_NAME ='" + UserName + "'", cnnwim.dbcon);

dbadapter.Fill(ds);

LogonUser.ID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"].ToString());

LogonUser.UserName = ds.Tables[0].Rows[0]["USER_NAME"].ToString();

LogonUser.CoId = Convert.ToInt32(ds.Tables[0].Rows[0]["CO_ID"].ToString());

LogonUser.Langu = ds.Tables[0].Rows[0]["LANGU"].ToString();

LogonUser.DepartmentId = Convert.ToInt32(ds.Tables[0].Rows[0]["DEPARTMENT_ID"].ToString());

LogonUser.DepartmentDescr = ds.Tables[0].Rows[0]["DEPARTMENT"].ToString();

//LogonUser.UserGroup = ds.Tables[1];

_errmsg = "";

_logonstatus = "success";

}

catch (Exception e)

{

LogonUser = null;

_errmsg = e.Message;

_logonstatus = "error";

}

return LogonUser;


}

}

}

 The WimUser Class

namespace WIM2008_Web.App_Code.wim.security.data

{

public class WimUser

{

private String _password;

private Int32 _id;

private Int32 _CoId;

private String _langu;

private Int32 _departmentid;

private String _departmentdescr;

public String UserName { get; set; }

public String UserFullName { get; set; }

public String Password

{

get { return _password; }

set { _password = value; }

}

public Int32 ID

{

get { return _id; }

set { _id = value; }

}

public Int32 CoId

{

get { return _CoId; }

set { _CoId = value; }

}

public String Langu

{

get { return _langu; }

set { _langu = value; }

}

public Int32 DepartmentId

{

get { return _departmentid; }

set { _departmentid = value; }

}

public String DepartmentDescr

{

get { return _departmentdescr; }

set { _departmentdescr = value; }

}

public String ProviderUserKey { get; set; }

public Boolean IsOnline { get; set; }

public Boolean IsLockedOut { get; set; }

public Boolean IsApproved { get; set; }

public String PasswordQuestion { get; set; }

public String Email { get; set; }

public DateTime CreationDate { get; set; }

public String Comment { get; set; }

}

}

As long as i call the WimUser and the (WimUser)Session["wimuser"] from within a class or a code page it works. No problems.

But if i call a class with the objectDataSource and the WimUser is called from within the class i get the error...

Thanks for the answers so-far

Aprreciate it


 

0
fdepijper
1/27/2009 6:52:20 AM
Reply:

Similar Artilces:

Unable to cast object of type 'System.Object[]' to type 'System.Data.DataView'.
I am tring to retieve a single node from my BLL code which retrieve one instane of Repot object:DataView dv = (DataView)objBoutPrep.Select();I am getting error:Unable to cast object of type 'System.Object[]' to type 'System.Data.DataView'. The BLL code returns onle one object and not a list of objects.Please help Client code: <asp:ObjectDataSource ID="objBoutPrep" runat="server" SelectMethod="GetRByID" UpdateMethod="UpdateT" TypeName="MB.K.BLL.G.Report"> <SelectParameters> <asp:Query...

Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.
what is my problem? I'm working with GridView for sorting The error message is that "Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'".... Dim m_DataTable As DataTable = GridView1.DataSource How can I change the code above?   Well let's see, if your DataSource is a DataView, you can get its associated DataTable object using the .Table property: Dim m_DataTable As DataTable = GridView1.DataSource.Table or in a land of strict typing:  Dim m_DataTable As DataTable = CType(GridView1.DataSource, System.Data.DataView).Table   Hope tha...

Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.
When I click the sort hyperlink, I got this error mesg: Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.  in line 5.How do I fix this? Thanks. 1 Protected Sub GVCRlisting_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GVCRlisting.Sorting 2 GridViewSortExpression = e.SortExpression 3 Dim pageIndex As Integer = GVCRlisting.PageIndex 4 5 GVCRlisting.DataSource = SortDataTable(GVCRlisting.DataSource, False) 6 GVCRlisting....

Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'.
Hi... I have a ListView which is nested in the ItemTemplate of another ListView. If a "status" value in the inner ListView = 1, then I'd like to hide the "Add to cart" link. However, the inner ListView's ItemDataBound event results in the error: "Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'." I've thoroughly searched the forums, but have not found a solution to this seemingly straightforward problem. Here is the code; the error occurs at line 8. 1 protected void L...

Unable to cast object of type 'System.Security.Principal.GenericIdentity' to type 'System.Web.Security.FormsIdentity'.
Hi Has anyone ever came across this problem before, the code was working ok this morning, but now it not and nothing has changed. Here is some test code string UserData = Ret.ToString();                        FormsAuthenticationTicket objTestForCookiesTicket;                        HttpCookie objTestForCookiesCookie;                        objTestForCookiesTicket = new FormsAuthenticationTicket(1,    ...

Unable to cast object of type 'System.Security.Principal.GenericIdentity' to type 'System.Web.Security.FormsIdentity'
I am getting the following error when i request the page in iis. it was working fine. if anybody give any solution for this is greatly appreciated   Server Error in '/' Application. Unable to cast object of type 'System.Security.Principal.GenericIdentity' to type 'System.Web.Security.FormsIdentity'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Unable to cast object of type '...

Unable to cast object of type 'System.Data.DataRowView' to type 'PRODUCT_WITH_IDRow'.
protected void dtlProducts_ItemDataBound(object sender, DataListItemEventArgs e) {GATEWAY.DSPRODUCT.PRODUCT_WITH_IDRow myRow = ((GATEWAY.DSPRODUCT.PRODUCT_WITH_IDRow)((System.Data.DataRowView)(e.Item.DataItem)).Row); problem ; GATEWAY.DSPRODUCT.PRODUCT_WITH_IDRow myRow =((GATEWAY.DSPRODUCT.PRODUCT_WITH_IDRow) ((System.Data.DataRowView)(e.Item.DataItem)).Row);   Unable to cast object of type 'System.Data.DataRowView' to type 'PRODUCT_WITH_IDRow'.   how to i resolve this problem ? Microsoft Certified Professional www.yazilimekibi.com ...

Unable to cast object of type 'System.Data.DataRow' to type 'OrderRow'
I'm trying to follow through the “Nested Data Web Controls” tutorial on this site but using data from my database rather than Northwind. For the two repeaters I am using an SQLDatasource for the outer repeater and an objectdatasource for the inner repeater.   I'm as far as the casting in the outer-repeaters ItemDataBound event but getting an InvalidCastException with the message:   “Unable to cast object of type 'System.Data.DataRow' to type 'OrderRow'”   As far as I can see, the only deviation from the tutorial is that I am using an SQLDatasource ...

Unable to cast object of type 'TYPE' to type 'TYPE'.
I've got a custom class and collection...I want to use them to databind a Grid, and persist the state using a Session variable.  However I keep getting the above error **Sometimes...There will be times when it works fine, and times when it totally craps out.System.InvalidCastException: Unable to cast object of type 'ApprovalCycleCollection' to type 'ApprovalCycleCollection'. This should work fine, no?  I want a property to use in all my foreach loops   public ApprovalCycleCollection NewApprovalCycle { get { if (Se...

Unable to cast object of type 'System.Web.Security.FormsIdentity' to type 'XXX'
I got following        protected void Application_AuthenticateRequest(object sender, EventArgs e)        {            if (Request.IsAuthenticated)            {                var user = Membership.GetUser();                var identity = new CustomIdentity(user.UserName, new Guid(user.ProviderUserKey.ToString()));&nb...

Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'
Hi, I am having this problem: Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'I have two repeaters: One is for a list of terms and the other show the definition. What I am trying to do is, highlight the selected term.Here is the relevant code which has this error:private Color SetButtonBackColor(object dataItem){ Response.Write("<br />In SetButtonBackColor Function"); Response.Write("<br>dataItem in SetColor is: " +(string)((DataRowView)dataItem)["TermIndex"]); string _initial =  (string) ((DataRowView)dataItem)["TermIndex"]; &n...

Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'.
In my code this doesn't work:prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2I get the error:Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'. But this does: prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int)prms(0).Value = 2Any reason why?  You code prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2 do evaluation: 1. if New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2, the result is Yes or No, 2. prms(0) =...

Unable to cast object of type 'System.IO.FileInfo' to type 'System.Data.DataRowView'.
This code below: Dim DomainVariable As String DomainVariable = Session("Domain")   If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem ThenDim FileRow As DataRowView = e.Item.DataItem Dim FileLink As HyperLink = e.Item.FindControl("FileHyperLink")Dim FileName As String = FileRow("Name")FileLink.NavigateUrl = String.Format("http://{0}/{1}", DomainVariable, FileName) FileLink.Text = FileRow("Name") End If IS GENERATING THIS ERROR............... Unable to cast object of type 'System.IO.Fil...

Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'BusinessObjectLayer.CustomPrincipal'
 Any ideas why I get this message: Server Error in '/' Application. Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'BusinessObjectLayer.CustomPrincipal'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'BusinessObjectLayer.CustomPrincipal'.Source Error: An unh...

Web resources about - Unable to cast object of type 'WIM2008_Web.App_Code.wim.security.data.User' to type 'WIM2008_Web.App_Code.wim.security.data.User' - asp.net.object-datasource

Resources last updated: 1/22/2016 8:46:45 AM