Results 1 to 9 of 9

Thread: [RESOLVED] An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParameterCol

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Resolved [RESOLVED] An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParameterCol

    I have the following code for my mapping file named Users
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       assembly="DEntities"
                       namespace="DEntities">
    
      <class name="Users" table="tUser" batch-size="10">
        <id name="UserID" column="UserID">
          <generator class="assigned"></generator>
        </id>
        
      <set name="UserRoles" cascade="all" lazy="true" inverse="true"  batch-size="4">
        <key column="UserRoleID" />
        <one-to-many class="DEntities.UserRoles" />
      </set>
    
        <property name="UserID" column="UserID"  ></property>
        <property name="UserName" column="UserName"  ></property>
        <property name="Password" column="Password"  ></property>    
        <property name="Email" column="Email"  ></property>    
        <property name="CreatedBy" column="CreatedBy"  ></property>    
        <property name="CreatedDate" column="CreatedDate"  ></property>    
        <property name="UpdatedBy" column="UpdatedBy"  ></property>    
        <property name="UpdatedDate" column="UpdatedDate"  ></property>    
        <property name="Status" column="Status"  ></property>    
        <property name="OrganizationID" column="OrganizationID"  ></property>       
    
      </class>
    </hibernate-mapping>
    and the following code for class named User
    Code:
    using System.Text;
    using System.Threading.Tasks;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    
    namespace DEntities
    {
        public class Users
        {
            public virtual IEnumerable<DEntities.UserRoles> UserRoles { get; set; }
    
            public Users()
            {
                UserRoles = new List<DEntities.UserRoles>();
            }
            public virtual int UserID { get; set; }
            public virtual string UserName { get; set; }
            public virtual string Email { get; set; }                
            public virtual string CreatedBy { get; set; }
            public virtual DateTime CreatedDate { get; set; }
            public virtual byte Status { get; set; }
            public virtual int OrganizationID { get; set; }
            [Required]
            [DataType(DataType.Password)]
            [Display(Name = "Password")]
            public virtual string Password { get; set; }
            public virtual string UpdatedBy { get; set; }
            public virtual DateTime UpdatedDate { get; set; }    
               
        }      
    }
    and the following code for View named Create
    Code:
    @model DEntities.Users 
    
    @{
        ViewBag.Title = "Create";
        int i =0;
    }
    
    <h2>Create</h2>
    
    @using (Html.BeginForm()) {
        @Html.ValidationSummary(true)
    
        <fieldset>
            <legend>tUser</legend>
            
            <div class="editor-label">
                @Html.LabelFor(users => users.UserName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.UserName)
                @Html.ValidationMessageFor(users => users.UserName)
            </div>
    
            <div class="editor-label">
                @Html.LabelFor(users => users.Password)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.Password)
                @Html.ValidationMessageFor(users => users.Password)
            </div>
    
            <div class="editor-label">
                @Html.LabelFor(users => users.Password)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.Password)
                @Html.ValidationMessageFor(users => users.Password)
            </div>
    
            <div class="editor-label">
                @Html.LabelFor(users => users.Email)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.Email)
                @Html.ValidationMessageFor(users => users.Email)
            </div>
    
            <div class="editor-label">
                @Html.LabelFor(users => users.CreatedDate)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.CreatedDate)
                @Html.ValidationMessageFor(users => users.CreatedDate)
            </div>
    
            <div class="editor-label">
                @Html.LabelFor(users => users.CreatedBy)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.CreatedBy)
                @Html.ValidationMessageFor(users => users.CreatedBy)
            </div>
            
            <div class="editor-label">
                @Html.LabelFor(users => users.UpdatedDate)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.UpdatedDate)
                @Html.ValidationMessageFor(users => users.UpdatedDate)
            </div>
    
            <div class="editor-label">
                @Html.LabelFor(users => users.UpdatedBy)
            </div>
            <div class="editor-field">
                @Html.EditorFor(users => users.UpdatedBy)
                @Html.ValidationMessageFor(users => users.UpdatedBy)
            </div>
    
                @for (i = 0; i < ((Model ?? new DEntities.Users()).UserRoles ?? new List<DEntities.UserRoles>()).ToList().Count ; i++)
                {
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].UserRoleID)       
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].UserID)     
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].RoleID)     
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].CreatedBy)     
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].CreatedDate)   
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].UpdatedBy)   
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].UpdatedDate)   
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].Status)   
                @Html.HiddenFor(users => users.UserRoles.ToList()[i].OrganizationID)   
               }
           
            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>
    }
    
    <div>
        @Html.ActionLink("List of Users", "Index","UserMaintenance")
    </div>
    
    @section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
    }
    this is for to create a new User..but it gives an error as "An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParameterCollection."
    I am on this since last two days. Please any one can assist me on this.....

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    Any chance it gives a hint on what line the error happens on?

    I don't see any SqlCe code in there at all... or any parameter information for that matter... so I'm not sure what the issue is... but I don't think it's in the code you've posted.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    It happens in Repository

    public virtual DEntities.Users CreateUser(ISession session, DEntities.Users userToCreate)
    {
    try
    {
    // check whether the id is assigned to the object
    //if(String.IsNullOrEmpty(UserToCreate.UserId))
    if (userToCreate.UserID == 0)
    {
    userToCreate.UserID = userToCreate.UserID + 1;
    }
    else
    {
    sqlQuery = "SELECT MAX(UserId) FROM tUser";
    IQuery query = session.CreateSQLQuery(sqlQuery);
    IList<int> userid = query.List<int>();
    userToCreate.UserID = userid.ElementAt(0);
    userToCreate.UserID = userToCreate.UserID + 1;
    }
    session.BeginTransaction();
    session.Save(userToCreate);
    session.Flush();
    session.Transaction.Commit();
    }
    catch (Exception exp)
    {
    session.Transaction.Rollback();
    throw;

    }
    return userToCreate;
    }
    The error is throwing in the underlined and bold lines

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    The Object UserRoles in class Users returning null value..i think thats the problem but dont know how to resolve.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    Did you think that it would be more fun for us to work out where the error occurs for ourselves rather than you're pointing it out for us? If so, you were mistaken.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    I pointed the error line and error. And i dont think that you people sitting there and doing nothing except solving my errors, so i am not mistaken

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    1) It's happening on that line because you're rethrowing it... but that's not where the error is happening.
    2) I still don't see any calls to any database or parameters of any kind.
    3) Time to start using those debugging skills and dig through the code and calls until you find the source of the exception. But it's still not in the posted code.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    Quote Originally Posted by sanju4kk View Post
    I pointed the error line and error. And i dont think that you people sitting there and doing nothing except solving my errors, so i am not mistaken
    I posted without having seen the two prior posts.

    Try looking at the stack trace for the exception, which tells you exactly where the exception was thrown.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: An SqlCeParameter with ParameterIndex '10' is not contained by this SqlCeParamete

    The problem was in the following line in User class

    public virtual int UserID { get; set; }

    i removed this line and also changed the database from Combact SQLSERVER to SQLSERVER 2005.
    Now its working fine. Just need to create a function to get the last UserID from table and increment it by one

    Thank you guys for your time and effort on this thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width