Solved

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

Posted on 2011-03-09
6
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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 use and create new code templates in NetBeans IDE 8.0 for Windows.

726 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