471,315 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

C# express addition DataRow related warning

While experimenting with binding datasets to an MS DataGridView, I get
a warning that tells me that my DataRows are "either undeclared or was
never assigned". Assuming that I am reading the documentation
correctly, you are supposed to create a DataRow using the
"DataTable.NewRow()" method. This is what I do in my app. As a matter
of fact, the DataRow constructor appears to be protected so I can't
directly create it if I want to. Is this warning a bug in MS C#
express? Or am I doing something wrong? If I ignore the warning and
run the app, it works as expected. Just trying to sort out the best
way to remove this warning.

-Michael

Jan 3 '06 #1
3 1703
Michael,

Can you post the code? This error has little to do with the actual way
you create the data row, but rather, a variable that is not assigned
properly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mi************@hotmail.com" <ge******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
While experimenting with binding datasets to an MS DataGridView, I get
a warning that tells me that my DataRows are "either undeclared or was
never assigned". Assuming that I am reading the documentation
correctly, you are supposed to create a DataRow using the
"DataTable.NewRow()" method. This is what I do in my app. As a matter
of fact, the DataRow constructor appears to be protected so I can't
directly create it if I want to. Is this warning a bug in MS C#
express? Or am I doing something wrong? If I ignore the warning and
run the app, it works as expected. Just trying to sort out the best
way to remove this warning.

-Michael

Jan 3 '06 #2
mi************@hotmail.com wrote:
While experimenting with binding datasets to an MS DataGridView, I get
a warning that tells me that my DataRows are "either undeclared or was
never assigned". Assuming that I am reading the documentation
correctly, you are supposed to create a DataRow using the
"DataTable.NewRow()" method. This is what I do in my app. As a matter
of fact, the DataRow constructor appears to be protected so I can't
directly create it if I want to. Is this warning a bug in MS C#
express? Or am I doing something wrong? If I ignore the warning and
run the app, it works as expected. Just trying to sort out the best
way to remove this warning.

-Michael

You create a row by doing:

DataRow dr = dtDataTable.NewRow();

Nut after that you need to add that row to the table:

dtDataTable.Rows.Add(dr);

....because beleive it or not, the row created by NewRow doesn't belong to the table by default.

Hope it helps,
MuZZy
Jan 4 '06 #3
Here is the code. I know that it isn't good practice to put data
related code directly together with GUI code. This was just a simple
test to familiarize myself with the MS data related classes; search for
the string "DataRow dr = d.NewRow();" to jump to relavent section of
the code; I think I'm doing things by the book as per MS documentation,
but perhaps I'm missing something such that I'm getting the warning in
C# Express Edition; note that the code compiles and runs fine...
----------------------------------------------

using System.Data;

namespace Test
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.d = new System.Data.DataTable();
this.ds = new System.Data.DataSet();
this.dataGridView1 = new
System.Windows.Forms.DataGridView();
this.button1 = new System.Windows.Forms.Button();
this.clientIDDataGridViewTextBoxColumn = new
System.Windows.Forms.DataGridViewTextBoxColumn();
this.clientNameDataGridViewTextBoxColumn = new
System.Windows.Forms.DataGridViewTextBoxColumn();

((System.ComponentModel.ISupportInitialize)(this.d )).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.d s)).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.d ataGridView1)).BeginInit();
this.SuspendLayout();
//
// d
//
this.d.TableName = "Client";
//
// ds
//
this.ds.DataSetName = "ClientDB";
this.ds.Tables.AddRange(new System.Data.DataTable[] {
this.d});

d.Columns.Add("ClientID",
System.Type.GetType("System.Int32"));
d.Columns.Add("ClientName",
System.Type.GetType("System.String"));

DataRow dr = d.NewRow();
dr["ClientID"] = 2;
dr["ClientName"] = "Fidelity";
d.Rows.Add(dr);

//
// dataGridView1
//
this.dataGridView1.AllowUserToOrderColumns = true;
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeig htSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new
System.Windows.Forms.DataGridViewColumn[] {
this.clientIDDataGridViewTextBoxColumn,
this.clientNameDataGridViewTextBoxColumn});
this.dataGridView1.DataMember = "Client";
this.dataGridView1.DataSource = this.ds;
this.dataGridView1.Location = new System.Drawing.Point(139,
69);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(240,
150);
this.dataGridView1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(457, 71);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(154, 72);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// clientIDDataGridViewTextBoxColumn
//
this.clientIDDataGridViewTextBoxColumn.DataPropert yName =
"ClientID";
this.clientIDDataGridViewTextBoxColumn.HeaderText =
"ClientID";
this.clientIDDataGridViewTextBoxColumn.Name =
"clientIDDataGridViewTextBoxColumn";
//
// clientNameDataGridViewTextBoxColumn
//
this.clientNameDataGridViewTextBoxColumn.DataPrope rtyName =
"ClientName";
this.clientNameDataGridViewTextBoxColumn.HeaderTex t =
"ClientName";
this.clientNameDataGridViewTextBoxColumn.Name =
"clientNameDataGridViewTextBoxColumn";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(834, 663);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";

((System.ComponentModel.ISupportInitialize)(this.d )).EndInit();

((System.ComponentModel.ISupportInitialize)(this.d s)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.d ataGridView1)).EndInit();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Button button1;
private System.Data.DataTable d;
private System.Data.DataSet ds;
private System.Windows.Forms.DataGridViewTextBoxColumn
clientIDDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn
clientNameDataGridViewTextBoxColumn;
}
}

Jan 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.