C# obtain row values
-
In a C# 2010 application, I am working with data that is obtained from an excel spreadsheet 2007 or exccel 2010. I want to be ae to see all the values in a particular row. In the code below I want to see all the values in the row called dt.Rows[j]. Basically I want to know how to obtain all the values for the column called [k] in the statement dt.Rows[j][k]
System.Data.DataTable dt = tt.GetExcelDataTable();
for (int j = 0; j < dt.Rows.Count; j++)
dt.Rows[j][k].ToString();Can you tell me how I can see the values I am looking for?
-
In a C# 2010 application, I am working with data that is obtained from an excel spreadsheet 2007 or exccel 2010. I want to be ae to see all the values in a particular row. In the code below I want to see all the values in the row called dt.Rows[j]. Basically I want to know how to obtain all the values for the column called [k] in the statement dt.Rows[j][k]
System.Data.DataTable dt = tt.GetExcelDataTable();
for (int j = 0; j < dt.Rows.Count; j++)
dt.Rows[j][k].ToString();Can you tell me how I can see the values I am looking for?
This code will print your data one row in a line with data in each row comma separated
System.Data.DataTable dt = tt.GetExcelDataTable();
for (int j = 0; j < dt.Rows.Count; j++) {
string rowData = string.Empty;
for (int k = 0; k < dt.Columns.Count; k++) {
rowData += dt.Rows[j][k].ToString() + ", ";
}
Console.WriteLine(rowData);
} -
This code will print your data one row in a line with data in each row comma separated
System.Data.DataTable dt = tt.GetExcelDataTable();
for (int j = 0; j < dt.Rows.Count; j++) {
string rowData = string.Empty;
for (int k = 0; k < dt.Columns.Count; k++) {
rowData += dt.Rows[j][k].ToString() + ", ";
}
Console.WriteLine(rowData);
}I want to be able to see all the values while I am debugging the application. How would you accomplish this task?
-
I want to be able to see all the values while I am debugging the application. How would you accomplish this task?
The code I provided will print all the data one row in a line. However if you wish to see data in individual rows/columns, Visual Studio's debugging tools do a great job, just hover your mouse over the 'Rows' variable and Visual Studio will show you it's contents. Here[^] is a video that explains this feature.
-
I want to be able to see all the values while I am debugging the application. How would you accomplish this task?
You can keep the break point in line 1 of your code.
System.Data.DataTable dt = tt.GetExcelDataTable(); // line 1
for (int j = 0; j < dt.Rows.Count; j++)
dt.Rows[j][k].ToString();Now when the control reaches here, the line color changes to yellow. Press F10 now. Now, place the mouse over
dt
, you'll find a search icon, near the tip of the cursor. Click on that. It opens up the table for viewing. -
This code will print your data one row in a line with data in each row comma separated
System.Data.DataTable dt = tt.GetExcelDataTable();
for (int j = 0; j < dt.Rows.Count; j++) {
string rowData = string.Empty;
for (int k = 0; k < dt.Columns.Count; k++) {
rowData += dt.Rows[j][k].ToString() + ", ";
}
Console.WriteLine(rowData);
}I think your second
for
loop should have been edited after you pasted it. :rolleyes: -
I think your second
for
loop should have been edited after you pasted it. :rolleyes: