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. Cannot get data saved to my SQL dbase

Cannot get data saved to my SQL dbase

Scheduled Pinned Locked Moved C#
databaselearningcsharphelptutorial
2 Posts 2 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.
  • T Offline
    T Offline
    tvance929
    wrote on last edited by
    #1

    Hi everyone. I am on the LAST beginner tutorial on MSDN in C#. I have a couple questions. I am adding to my database with the code : this.cd_tableTableAdapter.Insert(cdName, cdDescription, image); this.cd_tableTableAdapter.Fill(this.cdTrackerDataSet.cd_table); This is SUPPOSED to write to my database and of course it shows up while the app is running, but it NEVER writes it to the database. I thought I remember from a previous tutorial that I had to do an actual UPDATE on the database to make sure it got written. Is this correct? Can someone help me permanently write this info to my dbase? Thanks!

    M 1 Reply Last reply
    0
    • T tvance929

      Hi everyone. I am on the LAST beginner tutorial on MSDN in C#. I have a couple questions. I am adding to my database with the code : this.cd_tableTableAdapter.Insert(cdName, cdDescription, image); this.cd_tableTableAdapter.Fill(this.cdTrackerDataSet.cd_table); This is SUPPOSED to write to my database and of course it shows up while the app is running, but it NEVER writes it to the database. I thought I remember from a previous tutorial that I had to do an actual UPDATE on the database to make sure it got written. Is this correct? Can someone help me permanently write this info to my dbase? Thanks!

      M Offline
      M Offline
      mdv113
      wrote on last edited by
      #2

      There are many ways to write data to the db: With SqlDataAdapter: FETCH DATA: SqlConnection con = new SqlConnection( connectionstring); SqlCommand command = new SqlCommand("select* from table", con); SqlDataAdapter adapter = new SqlDataAdapter(command); DataSet set = new DataSet(); adapter.Fill(set); CHANGE DATA: //get row to change DataRow row = set.Select("Columnx = 1"); row("Columnx") = 2; //Write to DB adapter.Update(set); //commit dataset set.AcceptChanges(); INSERT NEW ROW: DataRow newrow = set.Tables[0].NewRow(); newrow("Columnx") = x; newrow("Columny") = y; set.Tables[0].Rows.Add(newrow); adapter.Update(set); set.AcceptChanges(); Connection does not have to be opened nor closed when using adapter. You can also use direct SQL like so.. SqlConnection con = new SqlConnection( connectionstring); SqlCommand command = new SqlCommand("insert into table values(1,2) ", con); con.Open(); command.ExecuteNonQuery(); con.Close();

      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