dt.Rows[0]["column1"]
dt.Rows.Cast<DataRow>().Select(r => r.ItemArray).ToArray();
public class ClassName { public string Col1 { get; set; } public int Col2 { get; set; } } Now you can use a loop to fill a list and ToArray if you really need an array: ClassName[] allRecords = null; string sql = @"SELECT col1,col2 FROM some table"; using (var command = new SqlCommand(sql, con)) { con.Open(); using (var reader = command.ExecuteReader()) { var list = new List<ClassName>(); while (reader.Read()) list.Add(new ClassName { Col1 = reader.GetString(0), Col2 = reader.GetInt32(1) }); allRecords = list.ToArray(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)