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. C#
  4. problem with inserting data to access db

problem with inserting data to access db

Scheduled Pinned Locked Moved C#
databasehelp
7 Posts 6 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.
  • P Offline
    P Offline
    prasadbuddhika
    wrote on last edited by
    #1

    i'm trying to insert data to access db, and i did it, but the problem is after first insert when check the db data is there, then close the application and run it again the last inserted data is missing, what might be the problem.

    M D D 3 Replies Last reply
    0
    • P prasadbuddhika

      i'm trying to insert data to access db, and i did it, but the problem is after first insert when check the db data is there, then close the application and run it again the last inserted data is missing, what might be the problem.

      M Offline
      M Offline
      Md Marufuzzaman
      wrote on last edited by
      #2

      Actually the senerio is not clear, Probably you using a datatable with a disconnect recordset, Try to directly insert.

      Md. Marufuzzaman

      P 1 Reply Last reply
      0
      • M Md Marufuzzaman

        Actually the senerio is not clear, Probably you using a datatable with a disconnect recordset, Try to directly insert.

        Md. Marufuzzaman

        P Offline
        P Offline
        prasadbuddhika
        wrote on last edited by
        #3

        no i'm using oleDbDataAdapter1,dataSet11,oleDbConnection1 and following s the code

        DataRow dr = dataSet11.Table1.NewRow();
        dr["ic"] = txt1.Text;
        dr["DES"] = txt2.Text;
        dr["STKBAL"] = txt3.Text;

                oleDbConnection1.Open();
        
                dataSet11.Table1.Rows.Add(dr);
                oleDbDataAdapter1.Fill(dataSet11);
                oleDbDataAdapter1.Update(dataSet11,"table1");
                oleDbConnection1.Close();
        
        P M 2 Replies Last reply
        0
        • P prasadbuddhika

          i'm trying to insert data to access db, and i did it, but the problem is after first insert when check the db data is there, then close the application and run it again the last inserted data is missing, what might be the problem.

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Check all the stored procedures/SQL queries that are fired on the DB until you close your application. If the data has been inserted, it can vanish only if some command that does so is run. Had it been SQL server, Profiler would have helped you out. Don't know if it works with Access or there is something like that for Access DB too.

          1 Reply Last reply
          0
          • P prasadbuddhika

            no i'm using oleDbDataAdapter1,dataSet11,oleDbConnection1 and following s the code

            DataRow dr = dataSet11.Table1.NewRow();
            dr["ic"] = txt1.Text;
            dr["DES"] = txt2.Text;
            dr["STKBAL"] = txt3.Text;

                    oleDbConnection1.Open();
            
                    dataSet11.Table1.Rows.Add(dr);
                    oleDbDataAdapter1.Fill(dataSet11);
                    oleDbDataAdapter1.Update(dataSet11,"table1");
                    oleDbConnection1.Close();
            
            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Ummm... you're adding a DataRow to a DataTable in a DataSet then filling the DataSet with the contents of the database? Doesn't that wipe out the existing data in the DataSet? :confused: Other than that; why are you using a DataSet and a DataAdapter? You probably just want to use ExecuteNonQuery to add the data.

            1 Reply Last reply
            0
            • P prasadbuddhika

              i'm trying to insert data to access db, and i did it, but the problem is after first insert when check the db data is there, then close the application and run it again the last inserted data is missing, what might be the problem.

              D Offline
              D Offline
              Dino Mulahusic
              wrote on last edited by
              #6

              if you are running your application from visual studio and your access db file is added to project right click on your access db file, select properties, and set "copy to output directory" to "copy if newer" hope it helps :)

              Let there arise out of you a band of people inviting to all that is good, enjoining what is right, and forbidding what is wrong: They are the ones to attain felicity. Āli-'Imrān (The Family of Imran), 104.

              1 Reply Last reply
              0
              • P prasadbuddhika

                no i'm using oleDbDataAdapter1,dataSet11,oleDbConnection1 and following s the code

                DataRow dr = dataSet11.Table1.NewRow();
                dr["ic"] = txt1.Text;
                dr["DES"] = txt2.Text;
                dr["STKBAL"] = txt3.Text;

                        oleDbConnection1.Open();
                
                        dataSet11.Table1.Rows.Add(dr);
                        oleDbDataAdapter1.Fill(dataSet11);
                        oleDbDataAdapter1.Update(dataSet11,"table1");
                        oleDbConnection1.Close();
                
                M Offline
                M Offline
                MumbleB
                wrote on last edited by
                #7

                I would have thought that you might want to Open the Connection first??

                Excellence is doing ordinary things extraordinarily well.

                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