Solved

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

Posted on 2011-03-09
6
286 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
ID: 35083003
Looks ok to me. Are you having a problem with it?
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 250 total points
ID: 35083032
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
ID: 35083039
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 10

Expert Comment

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

Expert Comment

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

Author Closing Comment

by:Mr_Shaw
ID: 35083081
thanks
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

821 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