Copy Dataset /DataTable Column data to ArrayList / Array

Suppose You are getting data in DataSet DataTable and you want to get /copy that data from the particular DataTable’s specific Columnn contents to ArrayList then you need to do following steps.

DataSet dsFields = new DataSet();

string strQry = @” SELECT * FROM XYZ”;

// Settings.ConnectionString is where the Connection String is stored.                                                                                         dsFields = OracleHelper.ExecuteDataset(Settings.ConnectionString, CommandType.Text, strQry);

ArrayList arrProperties = new ArrayList();

foreach (DataRow row in dsFields.Tables[0].Rows) {



You will get ArrayList ‘arrProperties’ filled with the data of Column REQUIRED_COLUMN_NAME of Table[0]
Also If you want to Copy the same contents to Array from ArrayList then

string[] PropertiesArray = (string[])arrProperties.ToArray(typeof(string));

Here we are using string[])arrProperties.ToArray(typeof(string) because we are copying to Array of type string[] so need to be casted with string[] and need to mention the Type of the location to be copied.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s