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. I realy need help

I realy need help

Scheduled Pinned Locked Moved C#
helpgraphicsdocker
6 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    Sakkijha
    wrote on last edited by
    #1

    hi i have the folloeing code . it always give me this error : ERROR: Object reference not set to an instance of an object. here is the code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Final { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.DataGrid dataGrid1; private DataSet DS; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.dataGrid1 = new System.Windows.Forms.DataGrid(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(80, 88); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(216, 88); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 1; this.textBox1.Text = ""; // // dataGrid1 // this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(56, 152); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(304, 152); this.dataGrid1.TabIndex = 2; //

    R S 2 Replies Last reply
    0
    • S Sakkijha

      hi i have the folloeing code . it always give me this error : ERROR: Object reference not set to an instance of an object. here is the code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Final { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.DataGrid dataGrid1; private DataSet DS; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.dataGrid1 = new System.Windows.Forms.DataGrid(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(80, 88); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(216, 88); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 1; this.textBox1.Text = ""; // // dataGrid1 // this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(56, 152); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(304, 152); this.dataGrid1.TabIndex = 2; //

      R Offline
      R Offline
      Rein Hillmann
      wrote on last edited by
      #2

      There are two quick solutions: 1) Add the following line to AddRc(): test.TableName = "test"; 2) OR change the following line in button1_Click() DataTable Dtable = DS.Tables["test"].Copy(); to DataTable Dtable = DS.Tables[0].Copy(); Essentially you're trying to reference a table called test which does not exist (even though the object you created was called test - it does not mean the table name will be set to "test").

      S 1 Reply Last reply
      0
      • S Sakkijha

        hi i have the folloeing code . it always give me this error : ERROR: Object reference not set to an instance of an object. here is the code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Final { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.DataGrid dataGrid1; private DataSet DS; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.dataGrid1 = new System.Windows.Forms.DataGrid(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(80, 88); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(216, 88); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 1; this.textBox1.Text = ""; // // dataGrid1 // this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(56, 152); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(304, 152); this.dataGrid1.TabIndex = 2; //

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        It would be good to know which line of your code produces the error. Anyway, by the given error message it's obvious that you try to use an object which wasn't instanciated yet. So look which line causes the error and verify if you instanciated every object used there.


        www.troschuetz.de

        S 1 Reply Last reply
        0
        • R Rein Hillmann

          There are two quick solutions: 1) Add the following line to AddRc(): test.TableName = "test"; 2) OR change the following line in button1_Click() DataTable Dtable = DS.Tables["test"].Copy(); to DataTable Dtable = DS.Tables[0].Copy(); Essentially you're trying to reference a table called test which does not exist (even though the object you created was called test - it does not mean the table name will be set to "test").

          S Offline
          S Offline
          Sakkijha
          wrote on last edited by
          #4

          hi thanx 4 u r help this fixe the problem . but i have a new problem now which is : when i click the button 4 the first time the row will be added to the datagrid and i can C it but when i click the button again nothing happen and no data added to the data grid ?!!! any idea ? ? ? ?

          R 1 Reply Last reply
          0
          • S Stefan Troschuetz

            It would be good to know which line of your code produces the error. Anyway, by the given error message it's obvious that you try to use an object which wasn't instanciated yet. So look which line causes the error and verify if you instanciated every object used there.


            www.troschuetz.de

            S Offline
            S Offline
            Sakkijha
            wrote on last edited by
            #5

            hi i solve that problem but a new problem occure : when i click the button 4 the first time the row will be added to the datagrid and i can C it but when i click the button again nothing happen and no data added to the data grid ?!!! any idea ? ? ? ?

            1 Reply Last reply
            0
            • S Sakkijha

              hi thanx 4 u r help this fixe the problem . but i have a new problem now which is : when i click the button 4 the first time the row will be added to the datagrid and i can C it but when i click the button again nothing happen and no data added to the data grid ?!!! any idea ? ? ? ?

              R Offline
              R Offline
              Rein Hillmann
              wrote on last edited by
              #6

              Having quickly looked at the code.. I changed the following: 1) You don't want to clone the dataset since you won't be updating the one that is linked to the control. Change the line this.DS= addRCDataSet.Clone(); to this.DS= addRCDataSet; 2) I modified the whole button1_click() method to: private void button1_Click(object sender, System.EventArgs e) { object[] values = new object[1]; values[0] = textBox1.Text; DS.Tables["test"].Rows.Add(values); } This just seemed a lot simpler to me - your earlier method was giving me problems.

              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