I realy need help
-
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; //
-
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; //
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").
-
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; //
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.
-
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").
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 ? ? ? ?
-
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.
-
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 ? ? ? ?
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.