473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1795
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MLH | last post by:
I'm trying to overcome the pop-up warning issued by Outlook Express when an Access application uses SendObject to mail an attachment (report object converted to an rtf file) to a specified...
1
by: Marcel Sottnik | last post by:
Hello group Maybe this is not the right NG, but this problem seems to me to be more language related than ADO.NET. How can I write the constructor for specialization of DataRow which will...
2
by: siedem | last post by:
Hi I have to write a plugin to MS Outlook Express and MSN Messenger. Does anybody have any examples or documentation related with this topic? thanks in advance P.
3
by: sgottenyc | last post by:
Hello, Has anyone had any success running SQL Server Express on Vista with Apache via PHP? My PHP works fine, Apache works fine, and SQL Server Express works fine in Management Studio, but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.