473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting a column from from a datatable

I am not sure how to get a column from a datatable, I cannot use foreach.
DataColumn dataColumn = DataColumn TEXTDT.Columns[2+columns].ColumnName.Trim();



if (rows < TEXTDT.Rows.Count) // this will prevent rows to exceed number of rows in TEXTDT
{
// Insert each answer
DataColumn dataColumn = DataColumn TEXTDT.Columns[2+columns].ColumnName.Trim();

string answer;


if ((dataColumn.ColumnName != "QUEST") && (dataColumn.ColumnName != "S_DAT"))
{
// One column
if ((TEXTDT.Rows[rows][dataColumn.ColumnName] != DBNull.Value) && (dataColumn.ColumnName == var.name.Trim()))
{
answer = TEXTDT.Rows[rows][dataColumn.ColumnName].ToString();
projectQuestionToDatabase.ProjectResponseandRespon dentToDB(TEXTDT.Rows[rows], answer, intId, Convert.ToInt32(rows));
}
}

if (columns + 2 == TEXTDT.Columns.Count)
columns = 0;
}
if (rows < TEXTDT.Rows.Count) // this will prevent rows to exceed number of rows in TEXTDT
{
// Insert each answer
DataColumn dataColumn = TEXTDT.Columns[2+columns];
string answer;



if ((dataColumn.ColumnName.Trim() != "QUEST") && (dataColumn.ColumnName.Trim() != "S_DAT"))
{
// One column
if ((TEXTDT.Rows[rows][dataColumn.ColumnName.Trim()] != DBNull.Value) && (dataColumn.ColumnName.Trim() == var.name.Trim()))
{
answer = TEXTDT.Rows[rows][dataColumn.ColumnName.Trim()].ToString();
projectQuestionToDatabase.ProjectResponseandRespon dentToDB(TEXTDT.Rows[rows], answer, intId, Convert.ToInt32(rows));
}
}

if (columns + 2 == TEXTDT.Columns.Count)
columns = 0;
}
rows++;
columns++;
It is crashing on this line
if ((TEXTDT.Rows[rows][dataColumn.ColumnName.Trim()] != DBNull.Value) && (dataColumn.ColumnName.Trim() == var.name.Trim()))
Oct 6 '06 #1
1 2299
why can't you use foreach?
Expand|Select|Wrap|Line Numbers
  1. foreach(DataColumn dc in DataTable.Columns)
  2. {
  3.    if(dc.ColumnName == "What you're looking for")
  4.    {
  5.      //do something
  6.     }
  7. }
  8.  
Oct 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
6
by: melanieab | last post by:
Hi, Easy question. It seems to me that I'm following the examples correctly, but apparently I'm not. I'm trying to retrieve the data from a row called "row" and a column called "File". This is...
1
by: Rippo | last post by:
I am returning a datatable from a stored procedure and then iterating through the columns. I am trying to find out if a column has the sql data type of ntext. In .net the datatype of a sql ntext...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
4
by: Joe Schmoe | last post by:
All I want to to be able to take a two-column DataReader (One column with the Item ID number, the other with Item Description text) and load it into a Windows Forms ComboBox (Set to DropDownList...
4
by: tshad | last post by:
I have a DataTable which has the headings in row 0. I do the following: PayDates.DataSource=mDt; PayDates.DataTextField= "Pay Date"; PayDates.DataValueField="Pay Date"; PayDates.DataBind();...
4
by: darrel | last post by:
I can grab a random number in vb.net like this: Dim RandomClass As New Random Dim RandomNumber As Integer RandomNumber = RandomClass.Next(1, 26) However, what I want is a random number. Short...
4
by: =?Utf-8?B?TWlrZSBE?= | last post by:
I read the CSV file into a DataTable. This is so I can fix invalid dates and other data I don't want in the database. Then I use SqlBulkCopy to insert the data into the SQL database. All the...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
4
by: vinod allapu | last post by:
Hi all, I am displaying a gridview containing an UPDATE button. On clicking the button i need to redirect to another page. Here I am unable to find the row index of a clicked record button. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.