Solved

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

Posted on 2011-03-09
6
282 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to pass connection string through config 2 26
What .NET URL re-routing tool did I use? 2 37
Vb. Net application freezes 9 30
Wav problem 4 19
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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

867 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

18 Experts available now in Live!

Get 1:1 Help Now