Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. No parameterless constructor defined for this object.

No parameterless constructor defined for this object.

Scheduled Pinned Locked Moved ASP.NET
htmlhelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    firestoper
    wrote on last edited by
    #1

    Hi Guru's Im using ObjectDataSource for filling up the GridView, I'm just moving in on using objectDataSource, I find it handy since it trims up my code. After placing the requirement I'm encountering this issue No parameterless constructor defined for this object. Please let me know what when wrong? Regards Dom

    P T 2 Replies Last reply
    0
    • F firestoper

      Hi Guru's Im using ObjectDataSource for filling up the GridView, I'm just moving in on using objectDataSource, I find it handy since it trims up my code. After placing the requirement I'm encountering this issue No parameterless constructor defined for this object. Please let me know what when wrong? Regards Dom

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      The class doesn't have a zero parameter constructor. Some object that you are using requires a zero parameter constructor (even if it doesn't use it).

      Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      • F firestoper

        Hi Guru's Im using ObjectDataSource for filling up the GridView, I'm just moving in on using objectDataSource, I find it handy since it trims up my code. After placing the requirement I'm encountering this issue No parameterless constructor defined for this object. Please let me know what when wrong? Regards Dom

        T Offline
        T Offline
        ToddHileHoffer
        wrote on last edited by
        #3

        Here's the deal. Any serializable object must have a parameterless constuctor. For the Object Oriented beginner that means. Class MyDataOject { public MyDataOject() { //parameterless consturctor } } This is so that the object can be serialized to XML. Also you can not not have read only properties for the same reason. If a property is read only you can't recreate the object from xml. The objectDataSource probably serializes your class behind the scenes.

        I didn't get any requirements for the signature

        F 1 Reply Last reply
        0
        • T ToddHileHoffer

          Here's the deal. Any serializable object must have a parameterless constuctor. For the Object Oriented beginner that means. Class MyDataOject { public MyDataOject() { //parameterless consturctor } } This is so that the object can be serialized to XML. Also you can not not have read only properties for the same reason. If a property is read only you can't recreate the object from xml. The objectDataSource probably serializes your class behind the scenes.

          I didn't get any requirements for the signature

          F Offline
          F Offline
          firestoper
          wrote on last edited by
          #4

          Hmm basically I doing a layman work which is trying to convert my DAL (data access layer) functions to objectDataSource properties, the function I'm calling accepts one argument which sometimes can be null / 0 since its optional. Below is my function as well as the DAL that it calls Public Function fill(Optional ByVal orderID As Integer = 0) As DataTable Dim cmd As SqlCommand cmd = New SqlCommand Dim da As SqlDataAdapter da = New SqlDataAdapter Dim dt As DataTable Try dt = New DataTable cmd.Connection = _SQLConnection cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "nw_spSelectOrders" cmd.Transaction = _SQLTransaction If Not orderID.Equals(0) Then cmd.Parameters.Add(New SqlParameter("@orderID", SqlDbType.Int)) cmd.Parameters("@orderID").Direction = ParameterDirection.Input cmd.Parameters("@orderID").Value = orderID End If da.SelectCommand = cmd da.Fill(dt) If Not dt.Rows.Count > 0 Then Throw New Exception("no record") Else Return dt End If Catch ex As Exception Throw New Exception(ex.Message) Finally cmd.Dispose() da.Dispose() End Try End Function SP for the function above: 0 - returns all data SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO alter PROCEDURE nw_spSelectOrders ( @orderID int = 0 ) as begin Select o.orderID, od.quantity, od.unitprice, od.unitprice from orders as o left outer join [order details] as od on o.orderid = od.orderid where case when @orderID = 0 then 'selected' else case when o.orderID = @orderID then 'selected' else 'not selected' end end= 'selected' end Whats wrong with passing 0? when I explicitly place orderID number I get result but passing 0 nada.. Please advice Thanks Guys -- modified at 20:49 Tuesday 11th September, 2007

          S 1 Reply Last reply
          0
          • F firestoper

            Hmm basically I doing a layman work which is trying to convert my DAL (data access layer) functions to objectDataSource properties, the function I'm calling accepts one argument which sometimes can be null / 0 since its optional. Below is my function as well as the DAL that it calls Public Function fill(Optional ByVal orderID As Integer = 0) As DataTable Dim cmd As SqlCommand cmd = New SqlCommand Dim da As SqlDataAdapter da = New SqlDataAdapter Dim dt As DataTable Try dt = New DataTable cmd.Connection = _SQLConnection cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "nw_spSelectOrders" cmd.Transaction = _SQLTransaction If Not orderID.Equals(0) Then cmd.Parameters.Add(New SqlParameter("@orderID", SqlDbType.Int)) cmd.Parameters("@orderID").Direction = ParameterDirection.Input cmd.Parameters("@orderID").Value = orderID End If da.SelectCommand = cmd da.Fill(dt) If Not dt.Rows.Count > 0 Then Throw New Exception("no record") Else Return dt End If Catch ex As Exception Throw New Exception(ex.Message) Finally cmd.Dispose() da.Dispose() End Try End Function SP for the function above: 0 - returns all data SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO alter PROCEDURE nw_spSelectOrders ( @orderID int = 0 ) as begin Select o.orderID, od.quantity, od.unitprice, od.unitprice from orders as o left outer join [order details] as od on o.orderid = od.orderid where case when @orderID = 0 then 'selected' else case when o.orderID = @orderID then 'selected' else 'not selected' end end= 'selected' end Whats wrong with passing 0? when I explicitly place orderID number I get result but passing 0 nada.. Please advice Thanks Guys -- modified at 20:49 Tuesday 11th September, 2007

            S Offline
            S Offline
            StylezHouse
            wrote on last edited by
            #5

            Uhh please advise what? The error is REALLY descriptive, and two people here have given you the answer. I advise you learn .NET or something, if you can't even figure out what a paremeterless constructor is.

            F 1 Reply Last reply
            0
            • S StylezHouse

              Uhh please advise what? The error is REALLY descriptive, and two people here have given you the answer. I advise you learn .NET or something, if you can't even figure out what a paremeterless constructor is.

              F Offline
              F Offline
              firestoper
              wrote on last edited by
              #6

              I don't mean to be harsh all of us do start from baby step, those two people has given helpful suggestions and you.. you simply throw snow ball and say I advise you learn .NET or something ... or something?? WAD! Big help anyways

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups