Mapping columns in a DataTable to a SQL table with SqlBulkCopy

You probably need some thing like public void BatchBulkCopy(DataTable dataTable, string DestinationTbl, int batchSize) { // Get the DataTable DataTable dtInsertRows = dataTable; using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity)) { sbc.DestinationTableName = DestinationTbl; // Number of records to be processed in one go sbc.BatchSize = batchSize; // Add your column mappings here sbc.ColumnMappings.Add(“field1″,”field3”); sbc.ColumnMappings.Add(“foo”,”bar”); … Read more

How to change results per page value in datatables

The fully correct answer would be to use both and display length to 5: $(document).ready( function(){ $(‘#table’).dataTable({ “iDisplayLength”: 5, “aLengthMenu”: [[5, 10, 25, 50, -1], [5, 10, 25, 50, “All”]] }); }); If you use JUST “iDisplayLength”, then the dropdown will not have that length in options later or when the page loads (instead you … Read more

The source contains no DataRows

ds.Tables[4] might, but the result of your linq-query might not, which is likely where the exception is being thrown. Split your method chaining to use interim parameters so you can be dead certain where the error is occurring. It’ll also help you check for existing rows before you call CopyToDataTable() and avoid said exception. Something … Read more

How to check if Datarow value is null

Check if the data column is not null with DataRow.IsNull(string columnName) if (!row.IsNull(“Int64_id”)) { // here you can use it safety long someValue = (long)row[“Int64_id”]; } There are overloads for it using the index of the column or if you have the instance of the DataColumn. If you are sure about the index, use the … Read more

Loop through the rows of a particular DataTable

For Each row As DataRow In dtDataTable.Rows strDetail = row.Item(“Detail”) Next row There’s also a shorthand: For Each row As DataRow In dtDataTable.Rows strDetail = row(“Detail”) Next row Note that Microsoft’s style guidelines for .Net now specifically recommend against using hungarian type prefixes for variables. Instead of “strDetail”, for example, you should just use “Detail”. … Read more

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