DataRow: Select cell value by a given column name

Which version of .NET are you using? Since .NET 3.5, there’s an assembly System.Data.DataSetExtensions, which contains various useful extensions for dataTables, dataRows and the like. You can try using row.Field<type>(“fieldName”); if that doesn’t work, you can do this: DataTable table = new DataTable(); var myColumn = table.Columns.Cast<DataColumn>().SingleOrDefault(col => col.ColumnName == “myColumnName”); if (myColumn != null) … Read more

How can I add a new column and data to a datatable that already contains data?

Just keep going with your code – you’re on the right track: //call SQL helper class to get initial data DataTable dt = sql.ExecuteDataTable(“sp_MyProc”); dt.Columns.Add(“NewColumn”, typeof(System.Int32)); foreach(DataRow row in dt.Rows) { //need to set value to NewColumn column row[“NewColumn”] = 0; // or set it to some other value } // possibly save your Dataset … Read more

Simple way to copy or clone a DataRow?

You can use ImportRow method to copy Row from DataTable to DataTable with the same schema: var row = SourceTable.Rows[RowNum]; DestinationTable.ImportRow(row); Update: With your new Edit, I believe: var desRow = dataTable.NewRow(); var sourceRow = dataTable.Rows[rowNum]; desRow.ItemArray = sourceRow.ItemArray.Clone() as object[]; will work

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)