Hi friends,
I want to pass a arryalist object to a method which inserts record to sql table. How do i add all the column names and values to this arraylist object and also check for the no of columns passed?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jean PaulRank #32 · 38.5K reputationPosted Nov 8, 2011, 10:01 PM EST
I can suggest some idea like:
1) Convert your object into an entity like Employee
public class Employee
{
public int Id;
public string Name;
}
2) Pass the employee object through ArrayList
ArrayList list = new ArrayList();
list.Add(new Employee() { Id = 1});
list.Add(new Employee() { Id = 2});
3) Invoke the Insert() method by specifying the properties assigned.. If you wanted to skip "Name", pass only "Id"
Insert(list, "Id");
Insert(ArrayList list, params string[] propertiesAssigned)
Sam HobbsRank #107 · 20.5K reputationPosted Nov 9, 2011, 5:04 PM EST
There are many ways to do that. A simple solution is to use a structure or class that has at least two members; a name member and a value member and then make an ArrayList of instances of the structure or class. Another possibility is to use the DataRow class.
Nethra R SRank #6,347 · 269 reputationPosted Nov 9, 2011, 5:44 PM EST
I have not worked with arraylist and as you said, i have a class with 2 properties for column name and column value. But i do not know what to do next. I want to use the arraylist itself so can you guide further or give an example
And yes the arraylist will contain all the columns of a single row