Questions tagged [system.data.datatable]

57 questions
24
votes
2 answers

Passing null into a DataTable from a single line conditional statement parsing string values

I have an app that loops through a fixed width text file, reads each line into a string variable and uses the .Substring() method to find data for a given field. For a given field, it checks to see if the contents are simply spaces, or if there is…
Tom Miller
  • 536
  • 1
  • 4
  • 14
18
votes
3 answers

Datatable.Dispose() will make it remove from memory?

I have researching through very simple code and get stuck on seeing the dispose() result of datatable Following is the code DataTable dt= new Datatable(); SqlCommand Cmd = new SqlCommand("sp_getData",SqlCon); SqlCommand.CommandType=…
Rajeev Kumar
  • 4,901
  • 8
  • 48
  • 83
16
votes
3 answers

Compare two DataTables and select the rows that are not present in second table

I have two DataTables and I want to select the rows from the first one which are not present in second one For example: Table A id column 1 data1 2 data2 3 data3 4 data4 Table B id column 1 data10 3 …
Catalin
  • 167
  • 1
  • 1
  • 7
6
votes
2 answers

c# - create a datatable from a class (not a list of instances)

This question concerns generics and types as well as datatables. The following snippet is around the net here and there, and creates a datatable based on a generic type: public static DataTable ListToDataTable(List list) { DataTable dt =…
Glinkot
  • 2,924
  • 10
  • 42
  • 67
5
votes
2 answers

Create a sequence of anonymous types from the rows in a DataTable

This is a "let's see if it can be done" exercise more than anything else. Suppose I have a DataTable with several columns. Using linq, is it possible to select the rows of the table such that the result will be a sequence of an anonymous type where…
Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48
5
votes
3 answers

Copy C# DataTable and convert all values to string

I have a DataTable with columns of different types. What I want is a DataTable that has the same column names but all values are strings. That is, if this is the first: Name Age ----------- John 31 Alice 27 Marge 45 where Name is a String…
Alex A.
  • 5,466
  • 4
  • 26
  • 56
3
votes
2 answers

How should I manage large DataTables?

For reasons that don't make a lot of sense (Read: Not my decision) I need to keep a large number of rows, about ~90,000, in a DataTable and I do not have the option of using a database. I need to be able to search the DataTable efficiently to find…
user50858
3
votes
2 answers

Get difference between two data-tables according to one column

I have the following scenario: Table A that has 50 records and Table B that has 2 records. I need to define a new table, say TableDiff which should contain 48 records from Table A that doesn't exist in Table B My problem is that Table A and Table B…
Alex
  • 5,971
  • 11
  • 42
  • 80
2
votes
2 answers

Best way to add a new column to a data table based on an existing column

I have a data-table with data. I need to add another column to the datatable having the same value of another column but with less precision. Ie the original column would be having value 12.123 but the new column will have value 12.12 What is the…
Ananth
  • 10,330
  • 24
  • 82
  • 109
2
votes
2 answers

How to combine data from datatables

I have filled my dataset from multiple xml files in C#.Net. As a result I have a dataset which contains multiple DataTables in it. All of them are having two columns each namely "ID" and "Name". These data tables can contain rows for same ids actoss…
Anil Soman
  • 2,443
  • 7
  • 40
  • 64
2
votes
2 answers

Creating Disconnected DataRows in .NET

How do you create DataRow instances that aren't tied to any particular DataTable instance? (EDIT: I know you can create DataRows using the DataTable.NewRow() method, but the problem is that I can't seem to disconnect the row from its parent table so…
plaureano
  • 3,139
  • 6
  • 30
  • 29
2
votes
1 answer

Extracting a subset of DataTable columns in C# and then sending them to browser client as a JSON string

Here's the scenario: C# middle tier webservice has the data sent from SQL Server in a System.Data.DataTable object. There are dozens of columns in the DataTable's columns collection. The browser client only needs to see about six of them. The…
Tim
  • 8,669
  • 31
  • 105
  • 183
2
votes
2 answers

Update query's where clause values from a datatable

I have this query: UPDATE A Set A.NUM = B.NUM FROM A JOIN B on A.ID = B.ID where A.Code in () A.Code values are from a datatable. How do I feed into this query?
Meidi
  • 562
  • 1
  • 8
  • 28
2
votes
1 answer

SetField cannot cast DBNull.Value to System.Int32

I'm still very new to C# so please bear with me. I have an Access database with a table that looks like this: ID1 ID2 Name ---------------------- 1111 1234567 Joe 2222 1234567 Patricia 3333 7654321 Laurie None of the fields contain null…
Alex A.
  • 5,466
  • 4
  • 26
  • 56
1
vote
0 answers

C# - DataTables - Column is of Type Control - Export to XML

QUESTION: Is there a way to export a DataTable to XML when the DataTable has a Column of type Control. I get an error stating that the controls cannot be serialized. I have read up on the whole concept of serialized and DataContacts from various…
1
2 3 4