Solved

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

Posted on 2011-03-09
6
285 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

803 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