Questions tagged [datacolumn]

212 questions
135
votes
12 answers

How To Change DataType of a DataColumn in a DataTable?

I have: DataTable Table = new DataTable; SqlConnection = new System.Data.SqlClient.SqlConnection("Data Source=" + ServerName + ";Initial Catalog=" + DatabaseName + ";Integrated Security=SSPI; Connect Timeout=120"); SqlDataAdapter adapter = new…
rofans91
  • 2,970
  • 11
  • 45
  • 60
75
votes
5 answers

How do I get column names to print in this C# program?

I've cobbled together a C# program that takes a .csv file and writes it to a DataTable. Using this program, I can loop through each row of the DataTable and print out the information contained in the row. The console output looks like this: ---…
Kevin
  • 4,798
  • 19
  • 73
  • 120
53
votes
4 answers

DataColumn Name from DataRow (not DataTable)

I need to iterate the columnname and column datatype from a specific row. All of the examples I have seen have iterated an entire datatable. I want to pass a single row to a function to do a bunch of conditional processing. I want to separate the…
James Dean
  • 763
  • 1
  • 11
  • 22
21
votes
7 answers

How to get the SqlType of a column in a DataTable?

I have a DataTable obtained from a SQL DataBase, like this: using (SqlCommand cmd = new SqlCommand(query, _sqlserverDB)) { using (SqlDataAdapter adapter = new SqlDataAdapter(cmd)) { DataSet dataSet = new DataSet(); …
Roman
  • 1,691
  • 4
  • 18
  • 35
18
votes
3 answers

Determine if DataColumn is numeric

Is there a better way than this to check if a DataColumn in a DataTable is numeric (coming from a SQL Server database)? Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("Get_Some_Data"); DataSet ds =…
JustinStolle
  • 4,182
  • 3
  • 37
  • 48
18
votes
6 answers

Why DataColumn.Caption doesn't work?

I am trying to create a DataTable and bind it to a DataGridView. It works, but I can't set columns headers via the Caption property. It displays headers using the ColumnName ("City") instead. MSDN says that "You can use the Caption property to…
Alex P.
  • 3,697
  • 9
  • 45
  • 110
12
votes
4 answers

Create ADO.NET DataView showing only selected Columns

In C# & .NET, can one create a DataView that includes only a proper subset of the DataColumns of a given DataTable? In terms of relational algebra, one assigns a RowFilter in order to perform a "selection" operation (σ). How would one perform a…
JaysonFix
  • 2,515
  • 9
  • 28
  • 28
11
votes
1 answer

Add data row to datatable at predefined index

I have a datatable with one column: this.callsTable.Columns.Add("Call", typeof(String)); I then want to add a row to that datatable, but want to give a specific index, the commented number is the desired index: this.callsTable.Rows.Add("Legs");…
RSM
  • 14,540
  • 34
  • 97
  • 144
9
votes
2 answers

In WPF, how can I bind a datagrid column to a specific column of a datatable?

I have a Datatable with many columns, and a datagrid in which I need to display only a few of those columns. I need a codesample of how to do it. I found a whole bunch of examples telling me to turn AutoGenerateColumns to true and set the table as…
Andrey
  • 141
  • 1
  • 1
  • 4
8
votes
1 answer

C# binding datagridviewcomboboxcolumn to list display, formatting, preferred Size error

I have a table payments that has a null-able integer column named payMonth. I have the following class and list: public class months { public int payMonth { get; set; } public string monthName { get; set; } } lstMonths = new List
Hilal Al-Rajhi
  • 437
  • 6
  • 25
  • 49
8
votes
2 answers

How do I use IF/ELSE or CASE In DataColumn.Expression?

I have a table with 1 column: 'Status' I want to add in another column named 'Action', its value will be as follow: if Status = 'Yes' Then Action = 'Go', otherwise, Action = 'Stop'. I used this following code to add in column 'Action' but it didn't…
J - C Sharper
  • 1,567
  • 7
  • 23
  • 36
7
votes
4 answers

DataColumn set a default value

I am trying to set a default value for a DataColumn. How do you set a default value for DataColumn (column3) for the below code DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new…
user406151
  • 395
  • 3
  • 9
  • 15
6
votes
6 answers

how to find the max in a datacolumn of datetime?

I have a DataColumn of DateTime, I would like to know how I can have only the sooner date (min) and the later date (max). Thanks
francops henri
  • 507
  • 3
  • 17
  • 29
6
votes
6 answers

R get all categories in column

I have a large Dataset (dataframe) where I want to find the number and the names of my cartegories in a column. For example my df was like that: A B 1 car 2 car 3 bus 4 car 5 plane 6 plane 7 plane 8 plane 9 plane…
user3443063
  • 1,455
  • 4
  • 23
  • 37
5
votes
2 answers

Ignore optional columns on save

When I update a table from a Form through Autogenerated EF, if I remove some data-columns from the view form because I don't want to be editable, that columns are updated with null value, how can avoid this behavior? I read here: Entity Framework:…
Santiago
  • 2,190
  • 10
  • 30
  • 59
1
2 3
14 15