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. General Programming
  3. LINQ
  4. Insert opertion doesn't work

Insert opertion doesn't work

Scheduled Pinned Locked Moved LINQ
saleshelp
8 Posts 3 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.
  • A Offline
    A Offline
    amistry_petlad
    wrote on last edited by
    #1

    I am doing an insert opertion here in this code but when I opened table it shows blank rows. namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } } Any help would be appreciated. Thanks.

    A S 3 Replies Last reply
    0
    • A amistry_petlad

      I am doing an insert opertion here in this code but when I opened table it shows blank rows. namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } } Any help would be appreciated. Thanks.

      A Offline
      A Offline
      Andreas X
      wrote on last edited by
      #2

      Hi! Have you got the primary keys defined correct in the dbml file?

      Andreas Johansson
      IT Professional at Office IT Partner i Norrbotten Sweden
      What we don't know. We learn.
      What you don't know. We teach

      A 1 Reply Last reply
      0
      • A Andreas X

        Hi! Have you got the primary keys defined correct in the dbml file?

        Andreas Johansson
        IT Professional at Office IT Partner i Norrbotten Sweden
        What we don't know. We learn.
        What you don't know. We teach

        A Offline
        A Offline
        amistry_petlad
        wrote on last edited by
        #3

        Yes

        A 1 Reply Last reply
        0
        • A amistry_petlad

          Yes

          A Offline
          A Offline
          Andreas X
          wrote on last edited by
          #4

          Have you tried to instansiate the DataContext object within the method?

          Andreas Johansson
          IT Professional at Office IT Partner i Norrbotten Sweden
          What we don't know. We learn.
          What you don't know. We teach

          A 1 Reply Last reply
          0
          • A Andreas X

            Have you tried to instansiate the DataContext object within the method?

            Andreas Johansson
            IT Professional at Office IT Partner i Norrbotten Sweden
            What we don't know. We learn.
            What you don't know. We teach

            A Offline
            A Offline
            amistry_petlad
            wrote on last edited by
            #5

            Could you please refer the code in my first post ? and according can you provide me the hint?

            A 1 Reply Last reply
            0
            • A amistry_petlad

              Could you please refer the code in my first post ? and according can you provide me the hint?

              A Offline
              A Offline
              Andreas X
              wrote on last edited by
              #6

              You wrote:

              namespace DAL
              {
              public class DALCustomerEntery
              {
              NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext();

              public void InsertData(Customer objCustObj) //this object is coming from BOL
              {

              NorthwindMapping.Customer cust= new NorthwindMapping.Customer();

              cust.CustName = objCustObj.Custname;
              cust.amount = 25.89D;
              cust.Companyname = "My company";
              cust.Checkin = DateTime.Now;
              cust.Checkout = DateTime.Now;

              xy.Customers.InsertOnSubmit(cust);

              xy.SubmitChanges();

              }

              }
              }

              try to move the row NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); into the InsertData Method

              namespace DAL
              {
              public class DALCustomerEntery
              {

              public void InsertData(Customer objCustObj) //this object is coming from BOL
              {
              NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext();
              NorthwindMapping.Customer cust= new NorthwindMapping.Customer();

              cust.CustName = objCustObj.Custname;
              cust.amount = 25.89D;
              cust.Companyname = "My company";
              cust.Checkin = DateTime.Now;
              cust.Checkout = DateTime.Now;

              xy.Customers.InsertOnSubmit(cust);

              xy.SubmitChanges();

              }

              }
              }

              Andreas Johansson
              IT Professional at Office IT Partner i Norrbotten Sweden
              What we don't know. We learn.
              What you don't know. We teach

              1 Reply Last reply
              0
              • A amistry_petlad

                I am doing an insert opertion here in this code but when I opened table it shows blank rows. namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } } Any help would be appreciated. Thanks.

                S Offline
                S Offline
                sainath437
                wrote on last edited by
                #7

                try using this xy.InsertOnSubmit(cust); instead of xy.Customers.InsertOnSubmit(cust); hope this may work...

                1 Reply Last reply
                0
                • A amistry_petlad

                  I am doing an insert opertion here in this code but when I opened table it shows blank rows. namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } } Any help would be appreciated. Thanks.

                  S Offline
                  S Offline
                  sainath437
                  wrote on last edited by
                  #8

                  change xy.customers.insertonsubmit(cust); to xy.insertonsubmit(cust)

                  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