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. System.Data.NoNullAllowedException

System.Data.NoNullAllowedException

Scheduled Pinned Locked Moved C#
helpdatabasewpfwcfannouncement
3 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

    Hi, I'm working in VS2003 and I've used the Sql DataAdapter Wizard to create a data connection, sql data adapter, stored procedures, and dataset in a winform. I can search and update okay but I get an error when I try to add a new record using the AddNew() Method against the dataset. Any help appreciated. static void Main() { Application.Run(new Form1()); } private void btnSearch_Click(object sender, System.EventArgs e) { sqlDataAdapter1.SelectCommand.Parameters["@Param2"].Value = txtBoxSPSearch.Text; dsStaffPhysicians1.Clear(); sqlDataAdapter1.Fill(dsStaffPhysicians1); } private void btnReset_Click(object sender, System.EventArgs e) { this.dsStaffPhysicians1.Clear(); ClearStaffPhysician(); } private void SetupStaffPhysician() { //Initialize Staff Physician Page panel1.Visible = true; this.cBoxSPLicenseState.DataBindings.Add(new System.Windows.Forms.Binding("SelectedIndex", this.dsStaffPhysicians1, "tblStaffPhysicians.docLicenseState")); } private void ClearStaffPhysician() { //Clears textboxes and dropdowns txtBoxSPFirstName.Text = ""; txtBoxSPMiddleName.Text = ""; txtBoxSPLastName.Text = ""; txtBoxSPUpin.Text = ""; txtBoxSPLicenseNumber.Text = ""; txtBoxSPSearch.Text = ""; cBoxSPLicenseState.SelectedIndex = 0; } private void menuItem2_Click(object sender, System.EventArgs e) { //Main menu -- Staff Physicians SetupStaffPhysician(); menuItem2.Enabled = false; } 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) { //Generates Error:System.Data.NoNullAllowedException //Column 'docLName' does not allow nulls. this.BindingContext[dsStaffPhysicians1, "tblStaffPhysicians"].AddNew(); } private void menuItem3_Click(object sender, System.EventArgs e) { Application.Exit(); } private void btnCommit_Click(object sender, System.EventArgs e) { //will need to do something here to commit insert } } }

    R 1 Reply Last reply
    0
    • R rich_wenger

      Hi, I'm working in VS2003 and I've used the Sql DataAdapter Wizard to create a data connection, sql data adapter, stored procedures, and dataset in a winform. I can search and update okay but I get an error when I try to add a new record using the AddNew() Method against the dataset. Any help appreciated. static void Main() { Application.Run(new Form1()); } private void btnSearch_Click(object sender, System.EventArgs e) { sqlDataAdapter1.SelectCommand.Parameters["@Param2"].Value = txtBoxSPSearch.Text; dsStaffPhysicians1.Clear(); sqlDataAdapter1.Fill(dsStaffPhysicians1); } private void btnReset_Click(object sender, System.EventArgs e) { this.dsStaffPhysicians1.Clear(); ClearStaffPhysician(); } private void SetupStaffPhysician() { //Initialize Staff Physician Page panel1.Visible = true; this.cBoxSPLicenseState.DataBindings.Add(new System.Windows.Forms.Binding("SelectedIndex", this.dsStaffPhysicians1, "tblStaffPhysicians.docLicenseState")); } private void ClearStaffPhysician() { //Clears textboxes and dropdowns txtBoxSPFirstName.Text = ""; txtBoxSPMiddleName.Text = ""; txtBoxSPLastName.Text = ""; txtBoxSPUpin.Text = ""; txtBoxSPLicenseNumber.Text = ""; txtBoxSPSearch.Text = ""; cBoxSPLicenseState.SelectedIndex = 0; } private void menuItem2_Click(object sender, System.EventArgs e) { //Main menu -- Staff Physicians SetupStaffPhysician(); menuItem2.Enabled = false; } 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) { //Generates Error:System.Data.NoNullAllowedException //Column 'docLName' does not allow nulls. this.BindingContext[dsStaffPhysicians1, "tblStaffPhysicians"].AddNew(); } private void menuItem3_Click(object sender, System.EventArgs e) { Application.Exit(); } private void btnCommit_Click(object sender, System.EventArgs e) { //will need to do something here to commit insert } } }

      R Offline
      R Offline
      Rob Graham
      wrote on last edited by
      #2

      The problem is in the underlying schema for the database. You either need to change the properties of the field 'docLName' to allow null values, or provide a value in the addnew() Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke

      R 1 Reply Last reply
      0
      • R Rob Graham

        The problem is in the underlying schema for the database. You either need to change the properties of the field 'docLName' to allow null values, or provide a value in the addnew() Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke

        R Offline
        R Offline
        rich_wenger
        wrote on last edited by
        #3

        Thanks for responding; I'd rather not change the schema if possible. Can you tell me how to 'provide a value in the addnew()'? I've been all over the MSDN and don't have a clue how to proceed. Any help greatly appreciated.

        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