If I have given names to different DataTable columns and
those column names are stored in a variable, then passing
that variable to the datatable how can i Enter different
values in those columns listed in that variable?? Please
explain me with an example.I am not getting it.



If I have given names to different DataTable columns and those column names are stored in a variab..

Answer / Anupriya Ekka

You can use the `Add()` method to add rows to a DataTable using a variable containing column names. Here's an example:

C#:
```csharp
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new DataColumn("Age") });
string[] columnNames = { "Name", "Age" };
for (int i = 0; i < 5; i++)
{
dt.Rows.Add(columnNames, "Person_" + i, i * 10);
}
```
Python:
```python
import pandas as pd
df = pd.DataFrame(columns=["Name", "Age"])
columns = ["Name", "Age"]
for i in range(5):
df = df.append({col: f"Person_{i}" for col in columns}, ignore_index=True)
```
In both examples, a DataTable (DataFrame in Python) is created with two columns named 'Name' and 'Age'. Then, a variable `columnNames` contains the column names. Using a loop, rows are added to the DataTable/DataFrame where each row's values are stored in variables prefixed with "Person_". The variables for each column's value are created using the same pattern as the column name.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Automation Testing AllOther Interview Questions

What could go wrong with test automation?

1 Answers  


how is mind q venkat training in testing for weekend or general batches.and any other good institutes in ameerpet

1 Answers  


How does load testing work for websites?

1 Answers  


what is are the difference between qtp and selenium ?

1 Answers  


What tools are available for support of testing during software development life cycle?

2 Answers  


What is hybrid automation?

1 Answers  


How do you identify the test cases which are suitable for automation?

1 Answers  


List some advantages and disadvantages of automation testing.

1 Answers  


How software testing is handled?

1 Answers  


hi friends.....please help me...i have very ambiguity which one be selected between selenium or ETL-TESTING..

1 Answers  


Is automation testing a black box testing or white-box testing?

1 Answers  


is there any Rational Functional Tester certification questions available?

1 Answers   Infosys,


Categories