Solved

Create a table and add a row.... is there anything wrong with the code?

Posted on 2011-03-09
6
280 Views
Last Modified: 2013-12-17
           DataTable dtbl = ds.Tables[0];
           
            DataTable   schemaDataTable = new DataTable();
            DataColumn  schemaDataColumn;
            schemaDataColumn = new DataColumn();
            schemaDataColumn.DataType = Type.GetType("System.String");
            schemaDataColumn.ColumnName = "ColumnName";
            schemaDataTable.Columns.Add(schemaDataColumn);




            DataRow row = schemaDataTable.NewRow();

            row["ColumName"] = "Name";
            schemaDataTable.Rows.Add(row);
0
Comment
Question by:Mr_Shaw
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
Looks ok to me. Are you having a problem with it?
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 250 total points
Comment Utility
There's a typo, row["ColumName"] = "Name"; should be row["ColumnName"] = "Name";.  Also consider:
DataTable schemaDataTable = new DataTable();
schemaDataTable.Columns.Add("ColumnName", typeof(string));
schemaDataTable.Rows.Add("Name");

Open in new window

0
 
LVL 10

Assisted Solution

by:John Claes
John Claes earned 250 total points
Comment Utility
it looks like there is nothing wrong.

but I would suggest to check the folowing Example

http://msdn.microsoft.com/en-us/library/system.data.datatable.newrow.aspx

What is the Reason why you ask the question?
* getting errors? what errors?
* getting Weird response? give example please


regards

poor beggar
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:John Claes
Comment Utility
@ tgerbert: Good looking.
Looked at it for 5 min and didn't see that.
0
 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
I copied & pasted it into a console project, Visual Studio found it for me. ;)
0
 

Author Closing Comment

by:Mr_Shaw
Comment Utility
thanks
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now