Store and retrieve objects - Please help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sudantha
    New Member
    • Mar 2007
    • 16

    #1

    Store and retrieve objects - Please help

    I need to store C# object and object id in sql server db. Ex, student object having stid, name, addr and retrieve it using the stid. Can anyone provide a solution please?
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    You have to be able to create a table on a server side. Connect to the database and use simple Insert to store data and Select to retrieve it.


    From your question I assume that you have very little knowledge of it and you need a lot to learn before starting project like this.


    Sorry... :(

    Comment

    • Sudantha
      New Member
      • Mar 2007
      • 16

      #3
      Originally posted by iburyak
      You have to be able to create a table on a server side. Connect to the database and use simple Insert to store data and Select to retrieve it.


      From your question I assume that you have very little knowledge of it and you need a lot to learn before starting project like this.


      Sorry... :(

      Hi,

      I want to know that, the thing i need to insert is an object. In this case the object of the student class. Then is should be stored in a db table as a binary in one column and the stid in the other column as the key. When it requires, it should be possilbe to retrive that object using the stid and use in the application. Hope its clarify the prob.

      Comment

      • iburyak
        Recognized Expert Top Contributor
        • Nov 2006
        • 1016

        #4
        No you don't save objects on a database side.
        You just save values in a table and when you will retrieve this data from a database you will be able to create empty object and assign values received from a database to it.

        1. Create a table:
        [PHP]Create table Student(
        stid int,
        name varchar(50),
        addr varchar(500))[/PHP]

        2. Store data from each object:
        [PHP]Insert into table Student values (StudentID_here , StudentName_her e, Address)[/PHP]

        3. Retrieve data and create an object
        [PHP]Select stid, name, address from Student where stid = StudentID_here[/PHP]

        Comment

        • Sudantha
          New Member
          • Mar 2007
          • 16

          #5
          Originally posted by iburyak
          No you don't save objects on a database side.
          You just save values in a table and when you will retrieve this data from a database you will be able to create empty object and assign values received from a database to it.

          1. Create a table:
          [PHP]Create table Student(
          stid int,
          name varchar(50),
          addr varchar(500))[/PHP]

          2. Store data from each object:
          [PHP]Insert into table Student values (StudentID_here , StudentName_her e, Address)[/PHP]

          3. Retrieve data and create an object
          [PHP]Select stid, name, address from Student where stid = StudentID_here[/PHP]

          Hi,

          Thanks, but here is an special requirement to store an object as i stated above. The application is developed using asp.net c#. Do you have any solution for it?

          Comment

          • CoolRiyaz
            New Member
            • Mar 2007
            • 12

            #6
            If you want to store the objects please read 'Object Serialization'.
            But you can not store it in db, they will be stored on hard disk

            Comment

            • Sudantha
              New Member
              • Mar 2007
              • 16

              #7
              Originally posted by CoolRiyaz
              If you want to store the objects please read 'Object Serialization'.
              But you can not store it in db, they will be stored on hard disk

              Hi, thanks for your guid. I will look more about object serialization

              Sudantha

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by CoolRiyaz
                If you want to store the objects please read 'Object Serialization'.
                But you can not store it in db, they will be stored on hard disk
                Thanks for your response! It's great to see new people adding their knowledge to the community. I believe, however, that you are wrong about not being able to store an object in the database. You can do all kinds of things with serialized object; send them over the network, save them to disk, and yes, they can be put in a DB.

                Comment

                • Sudantha
                  New Member
                  • Mar 2007
                  • 16

                  #9
                  Hi,
                  Thanks for everyone who replied for this problem posted by myself. Recenly I found a good article which provides an excellent answer for this question. Follow the link below anyone who is interested.



                  Thanks

                  Sudantha
                  Last edited by Banfa; Apr 8 '07, 10:21 PM. Reason: Email Address removed in accordance with posting guidelines

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by Sudantha
                    Hi,
                    Thanks for everyone who replied for this problem posted by myself. Recenly I found a good article which provides an excellent answer for this question. Follow the link below anyone who is interested.



                    Thanks

                    Sudantha
                    Thanks for posting the article!
                    Last edited by Banfa; Apr 8 '07, 10:22 PM. Reason: Email Address removed in accordance with posting guidelines

                    Comment

                    Working...