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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Fill After Insert Fails

Fill After Insert Fails

Scheduled Pinned Locked Moved C#
helpdatabasevisual-studiowpfwcf
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.
  • R Offline
    R Offline
    rich_wenger
    wrote on last edited by
    #1

    I've created a sqldataadapter, stored procedures, and a data set using the VS2003 IDE Wizard based on a select command with a single paramter; search and updates work fine. I've got non-null columns in my database so I had to create a new Datarow in the data set and update that to perform an insert. The problem is the follow-up fill (sqlDataAdapter1.Update(dsStaffPhysicians1) to repopulate the dataset errors. Any help would be greatly appreciated. Code Snippet Follows================================================= static void Main() { Application.Run(new Form1()); } private void menuItem2_Click(object sender, System.EventArgs e) { //Initialize Staff Physician Screen SetupStaffPhysician(); menuItem2.Enabled = false; } private void menuItem3_Click(object sender, System.EventArgs e) { //Exit Application Application.Exit(); } private void SetupStaffPhysician() { panel1.Visible = true; this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedIndex", this.dsStaffPhysicians1, "tblStaffPhysicians.docLicenseState")); } private void ClearStaffPhysicians() { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; comboBox1.SelectedIndex = 0; } private void btnSearch_Click(object sender, System.EventArgs e) { sqlDataAdapter1.SelectCommand.Parameters["@Param2"].Value = textBox3.Text; dsStaffPhysicians1.Clear(); sqlDataAdapter1.Fill(dsStaffPhysicians1); } private void btnReset_Click(object sender, System.EventArgs e) { this.dsStaffPhysicians1.Clear(); ClearStaffPhysicians(); } private void btnUpdate_Click(object sender, System.EventArgs e) { this.BindingContext[dsStaffPhysicians1, "tblStaffPhysicians"].EndCurrentEdit(); sqlDataAdapter1.Update(dsStaffPhysicians1); sqlDataAdapter1.Fill(dsStaffPhysicians1); } private void btnInsert_Click(object sender, System.EventArgs e) { try { ClearStaffPhysicians(); } catch(Exception exp) { MessageBox.Show("Error 001 " + exp.Message); } } private void btnCommit_Click(object sender, System.EventArgs e) { DataRow newStaffPhysician = dsStaffPhysicians1.Tables["tblStaffPhysicians"].NewRow(); newStaffPhysician["docLName"] = textBox3.Text; newStaffPhysician["docFName"] = textBox1.Text; newStaffPhysician["docMName"] = textBox2.Text; newStaffPhysician["docLicenseState"] = comb

    J 1 Reply Last reply
    0
    • R rich_wenger

      I've created a sqldataadapter, stored procedures, and a data set using the VS2003 IDE Wizard based on a select command with a single paramter; search and updates work fine. I've got non-null columns in my database so I had to create a new Datarow in the data set and update that to perform an insert. The problem is the follow-up fill (sqlDataAdapter1.Update(dsStaffPhysicians1) to repopulate the dataset errors. Any help would be greatly appreciated. Code Snippet Follows================================================= static void Main() { Application.Run(new Form1()); } private void menuItem2_Click(object sender, System.EventArgs e) { //Initialize Staff Physician Screen SetupStaffPhysician(); menuItem2.Enabled = false; } private void menuItem3_Click(object sender, System.EventArgs e) { //Exit Application Application.Exit(); } private void SetupStaffPhysician() { panel1.Visible = true; this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedIndex", this.dsStaffPhysicians1, "tblStaffPhysicians.docLicenseState")); } private void ClearStaffPhysicians() { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; comboBox1.SelectedIndex = 0; } private void btnSearch_Click(object sender, System.EventArgs e) { sqlDataAdapter1.SelectCommand.Parameters["@Param2"].Value = textBox3.Text; dsStaffPhysicians1.Clear(); sqlDataAdapter1.Fill(dsStaffPhysicians1); } private void btnReset_Click(object sender, System.EventArgs e) { this.dsStaffPhysicians1.Clear(); ClearStaffPhysicians(); } private void btnUpdate_Click(object sender, System.EventArgs e) { this.BindingContext[dsStaffPhysicians1, "tblStaffPhysicians"].EndCurrentEdit(); sqlDataAdapter1.Update(dsStaffPhysicians1); sqlDataAdapter1.Fill(dsStaffPhysicians1); } private void btnInsert_Click(object sender, System.EventArgs e) { try { ClearStaffPhysicians(); } catch(Exception exp) { MessageBox.Show("Error 001 " + exp.Message); } } private void btnCommit_Click(object sender, System.EventArgs e) { DataRow newStaffPhysician = dsStaffPhysicians1.Tables["tblStaffPhysicians"].NewRow(); newStaffPhysician["docLName"] = textBox3.Text; newStaffPhysician["docFName"] = textBox1.Text; newStaffPhysician["docMName"] = textBox2.Text; newStaffPhysician["docLicenseState"] = comb

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      This may not fit with the parameters of your application design, but the examples show the Fill command being executed before the Update. (So you could move the Fill command to the top of your btnCommit_Click function.) Also, for this type of problem, it is far more likely that you will get valuable help if you provide a detailed error message in your post. :) John
      "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

      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