datatable

How to select records from SQL DB that contain the same ID as a .NET datatable records

I'm loading a CSV file containing many thousands of rows into a .NET DataTable that looks something like this: MyLocalDataTable SequenceNo, Etc I have a table in an SQL database and I'd like to pull records into another datatable based on what I find in the CSV file. MySQLBDTable IdentityID, SequenceNo, Etc The SequenceNo is my...

How to bind dataGridView predefined columns with columns from sql statement (without adding new columns)?

Hey, Is there a elegant way, to bind predefined dataGridView columns with results from sql statement? Example: dataGridView1.Columns.Add("EID", "ID"); dataGridView1.Columns.Add("FName", "FirstName"); some sql like SELECT t.FirstName as FName, t.EmpID as EID FROM table t ... and then I call dataGridView1.DataSource = someDataSet.Tab...

set tag in DataGridViewRow from DataTable automatically

Is there a way to use a column of data from a DataTable to set the tag of a row automatically instead of having to iterate through each row in the DGV to manually assign it? MyDataGridView.DataSource = GetDataTable(); foreach (DataGridViewRow dgvr in MyDataGridView.Rows) { dgvr.Tag = (int)dgvr.Cells[0].Value; } I have a large amount ...

How do I specify what the column type a DataGridView chooses to use when using DataTable as its DataSource

I have a column in my DGV that is a custom type to display values of MyObjectType. My DataTable has the column created as MyObjectType, but the DGV creates a DataGridViewTextBox column and populates it with MyObjectType.ToString(); which is not the behavior I want. Can I either force the data to be loaded into preexisting columns; or...

Export DataTable to Excel File

Hi, I have a DataTable with 30+ columns and 6500+ rows.I need to dump the whole DataTable values into an Excel file.Can anyone please help with the C# code.I need each column value to be in a cell.To be precise,I need the exact looking copy of DataTable in an Excel File.Please help. Thanks, Vix ...

How do I implement a datatable "group by"?

I would like to implement a "Group By" for my datatable. Has any one any suggestions? update: c#, .net 2.0 ...

How do you calculate the size of a datatable object?

In C#, how can you calculate the size of a datatable object in memory? We're using this to store various data groups, and would like to perform some logging/monitoring to aid in tuning the system. However one of the pieces of information we need is the size of the datatable object. Any ideas? ...

Display specific data on asp.net webpage from a microsoft sql express data table

I have been looking around the internet for a way to display specific content from a sql data table. I was hoping that I could display the Content column according to the Id column value. ...

Remove all columns with no data from DataTable

If all the items for a particular column are empty, I want to remove that column from the DataTable. What's the most elegant way to do this operation on all columns in the DataTable? ...

List<object[]> using more memory than DataTable?

Guys, I've always believed that DataTable would consume more memory than a generic List. I am testing loading a DataTable and loading a List from a SQL Server query. In this case, the DataTable is consuming less memory. I'm getting the top 2000 rows and there are 134 fields per row. One binary field and the rest are standard varchar, in...

Concurrency violation updating a SQL database with a dataadapter

I'm having some trouble updating changes I made to a datatable via a dataadapter. I am getting "Concurrency violation: the UpdateCommand affected 0 of 10 rows" 'Get data Dim Docs_DistributedTable As New DataTable("Docs_Distributed") Dim sql = "SELECT DISTINCT CompanyID, SortKey, OutputFileID, SequenceNo, DeliveredDate, IsDeliveryCodeCou...

ASP.NET DataTable output problem

I can't for the life of me work out what I am doing wrong here, despite much searching on SO/Google. Basically I have a simple DataTable which is held in ViewState and adjusted during postbacks. When I try to write out the values, it is just an empty string. Please find below an abbreviated example of what I have - the output in this ca...

C# DataTable: Add new row throws error using AutoInc field

I have a collection List<Employee> employees; I use a DataTable, and load all the records (from MDB table) when Form1.Loads, and add these records to the List (Collection) so I work with them in memory. Now, when I add a new employee to the collection, I should add it also to the mdb table... so I do: DataRow rowemployee = Program...

Dataadapter update performance - do I need to use datatable.Getchanges?

This is a simple question, but I'm having trouble finding the answer. I have a large datatable of which I have updated many, but not all rows. I am using a dataadapter to update these changes to SQL server. Does the dataadapter send update queries only for the updated rows from the datatable, or does it send one for every row, and esc...

datatable not accepting the value of varbinary

the value buf has a datatype varbinary(max) and the value is 0x0000002D string buF = "0x" + BitConverter.ToString((byte[])dt.Rows[i]["BuF"]).Replace("-", ""); Label3.Text = buF; i use the value to find the fileid DataTable dt = new DataTable(); SqlConnection connection = new SqlConnection(); connection.Connec...

Viewing dataset contents without using dataset visualizer

In writing some tests for a project I'm working on, I found that the best way for me to get the data back I needed about whether the project was correct was to put results into an ADO.NET DataTable. I got sick of setting breakpoints and waiting for them to be hit so that I could use the DataSet Visualizer to see what my results were, an...

Problem with datatable bound to a datagridview

I've a datatable bound to a gridview. The datatable has the following data: JobID Site Job List --------- --------- --------- --------- 134 A job1 26 2241 A job2 25 124 A job3 26 244 B job1 12 154 B ads2 46 Am trying to take the count of distinct sites. So I write the following function: public void CreateAdmins(DataTable...

ADO .net 2.0: PrimaryKey not updated after calling DataAdapter.Update()

Hi, I came across a problem while updating a typed DataTable that has a primary key column. At some point in my code I fill DataTables (some of them have primary and foreign key columns) and then I insert the data of all DataTables in one transaction using DataAdapters and Update(). Because the typed DataTables do not allow the PrimaryK...

2 Datatables to 1

Hello, Let's say i have Datatable1 that has "Colum1" , "colum2" and another table, Datatable2 with "Colum3" , "colum4" I need to create Datatable3 that will contain all the columns "Colum1" , "colum2", "Colum3" , "colum4" I need something smart, like the DefaultView.ToTable() method that does it for one table. Thanks ...

How to fill a DataTable with a List(Of t) or convert a List(Of t) to a DataTable?

I have read many posts on this topic; among them and most recently .NET - Convert Generic Collection to Data Table. Unfortunately, all to no avail. I have a generic collection of structures : Private Structure MyStruct Dim sState as String Dim lValue as Long Dim iLayer as Integer End Structure Dim LOStates As New List(Of MyStruct) I...