datatable

C# - How do I sort a DataTable by date.

I have a datatable that has a date column, but I am stumped as to how to sort it by that column. Any suggestions? ...

C# Issue: What is the simplest way for me to load a .MDB file, make changes to it, and save the changes back to the original file?

My project that I am working on is almost finished. I am loading a .MDB file, displaying the contents on a DataGrid and attempting to get those changes on the DataGrid and save them back into the .MDB file. I am also going to create a function that allows me to take the tables from one .MDB file and save it to another .MDB file. Of cours...

C# Issue: How do I save changes made in a DataGridView back to the DataTable used?

I get a DataTable from a DataSet and then bind that DataTable to a DataGridView. Once the user edits the information on the DataGridView how do I take those changes and put them back into a DataTable that was used that I can then put back into my DataSet? I want to make a Save Button on my DataGrid that when pressed actually saves the c...

How do I structure an OleDbCommand Query so that I can take Tables from one .MDB, and replace them in another .MDB

I am trying to take tables from one Access Database File, add them to another Access Database file with the exact same structure but with different information. I need to overwrite any existing tables. I am almost done with my project this is last my brick wall. I am using a separate class file named DatabaseHandling.cs to work with the...

How to sort a DataView in a case-insensitive manner?

I have a DataTable. I'd like to sort its default view by a column name 'city'. I'd like the sort to be case-insensitive. Here is the code I have: DataTable dt = GetDataFromSource(); dt.DefaultView.Sort = "city asc"; MyReport.DataSource = dt.DefaultView; Thanks. ...

Why am I getting this error when trying to update an Access Database file (.mdb) with a Datatable:

I've been working on my issue for 30 hours. Each time I fix one thing a new error arises. All I want to do is take a DataTables from memory and simply update an Access .MDB file. Here is my code: using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.IO; using System.Linq; using System.T...

How can I run a query on a dataset that returns different columns to the table?

Hi again all, I'm trying to pull some data from a SQL table in my dataset using C#. In this case I do not need all the columns just a few specific ones, however as I am not pulling back a column with a mandatory NOT NULL, the copy of the table is throwing the exception "Failed to enable constraints. One or more rows contain values...

How to merge multiple datatables into one?

I have multiple excel files which I open as datatable I want to merge all this datatables single DataTable in .net. eg, Apr09.xls,May09.xls,Jun09.xls All have dataas follows Apr09.xls EMPCODE,PresentDays 0001 ,30 0002 ,21 May09.xls EMPCODE,PresentDays 0001 ,25 0002 ,30 New datatable will be as follows EMPCODE,PresentDa...

Error: <target>.ColumnName and <source>.ColumnName have conflicting properties: DataType property mismatch.

I am trying to merge multiple excel files using DataTable.Merge() option For Each fileName As String In Directory.GetFiles("C:\TEMP\", "*.xls") Dim connectionString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=""Excel 8.0;HDR=NO;IMEX=1;""", fileName) Dim adapter As...

How do I find similar column names using linq?

Hi I am trying to learn Linq, so I am not sure if this can be done. I am working on an import project So I decided to import data using DataSets. My challenge at this point: Having 2 DataTables with different schema, one of which contains my destination schema, and the other one my source schema. What I need to do is perform some...

DataTable to Generic List

public static IList<T> ConvertTo<T>(DataTable table) { if (table == null) { return null; } List<DataRow> rows = new List<DataRow>(); foreach (DataRow row in table.Rows) { rows.Add(row); } return ConvertTo<T>(rows); } public static ...

DataTable to Json using jquery

I'm trying to execute a web service which returns a DataTable with the following piece of code: $.ajax({ type: "POST", url: url, data: data, contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { //do things } }); If the webservice retur...

How to calculate sum of a DataTable's Column in LINQ (to Dataset)?

I'm just started to read up on LINQ and I want to start incorporating it into my code. I know how to compute the sum of a DataTable's column by either "Foreach"-ing through the rows or by doing a compute.sum on the specific column. How do I do the equivalent with LINQ to DataSet? ...

How would you know if this is an ordinal index or not?

Hi, I have seen this piece of code in an example via online using C# DataTable dt = ds.Tables["employees"]; dt.Rows[0]["city"] = "Wilmington"; My question is what is the zero stands for? is it an ordinal index or not? Thanks in advance! ...

Generic List to DataTable

Hi, I have few methods that returns different Generic Lists. Exists in .net any class static method or whatever to convert any list into a datatable? The only thing that i can imagine is use Reflection to do this. IF i have this: List<Whatever> whatever=new List<Whatever>(); (This next code doesnt work of course, but i would like...

Columns in a primary key on a datatable being re-ordered automatically?

I have a table named Permissions which is defined in a dataset named _permissionsSet and it has 3 columns: PermissionGroup, Permission, PermissionLevel (in that order) I set the primary key on the table to include all 3 columns like this DataColumn[] keys = new DataColumn[3]; keys[0] = _permissionsSet.Permissions.Colum...

Consuming Web Services - going from a Manual method to an automatic one using third party provided WSDL

A bit long, but, shorter than the first draft :) We have a small VB.net application that basically pulls information from our dBase and then exports this information to an .xls file. From this .xls file, in house agents then manually update a third party listing service (which maintains our current inventory) with the information conta...

ASP.NET Gridview with all records editable.

I thought this would be simple, but I sure am having a lot of trouble doing this: The title of this question may be a bit misleading. I don't have to use a gridview. In fact, I know the GridView is probably not the way to go on this. I just didn't know how else to title it. But, for now just consider: I have a very simple class called ...

ASP.NET - No Datakey on Gridview RowDeleting event!

I have a GridView just like this: <asp:GridView ID="gvwStudents" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" ShowHeader="False" onrowdeleting="gvwStudents_RowDeleting"> <Columns> <asp:BoundField DataField="FirstName" /> <asp:BoundField DataField="LastName" /> <asp:BoundField DataFiel...

How do I use System.Data.DataTableExtensions' CopyToDataTable method?

I'd like to create a data table given a List using the CopyToDataTable method available in DataTableExtensions. I've previously asked the question How do I transform a List into a DataSet? and got an exceptional answer from CMS which was to achieve what I wanted by creating an extension public static DataTable ToDataTable<T>(this IEnumer...