datacolumn

How to retrieve column values separately through sql data adapter class?

大兔子大兔子 提交于 2019-12-23 05:26:58
问题 I am trying to learn how to use sql data adapter ... I have coded the following to check how it works ... the problem is i want to retrieve values of 3 columns(DeptNo,DeptId,DeptName) of my database table "Sana" separately and display them in three separate text boxes ... Through the code mentioned below I am able to retrieve the value of entire tuple of data base table together what should I do to reach above mentioned result??? protected void Button1_Click(object sender, EventArgs e) {

Best way add a new column with sequential numbering in an existing data table

夙愿已清 提交于 2019-12-21 02:49:10
问题 I have a non empty datatable . What is the best way to add another column to it that has sequential numbering starting from 1. I tried the following code. But did not work. DataColumn dc = new DataColumn("Col1"); dc.AutoIncrement = true; dc.AutoIncrementSeed = 1; dc.AutoIncrementStep = 1; dc.DataType = typeof(Int32); dt.Columns.Add(dc); Will setting any expression help in this scenario ? Thanks in Advance 回答1: I think you could achieve that by using a 2nd "helper" data table that would

How to access an column with special characters using DataTable.Select()?

我与影子孤独终老i 提交于 2019-12-20 07:12:55
问题 I have a DataTable with column such as # of Students and would like to sort by this in descending order. Here is my code: ... dt.Columns.Add(new DataColumn("# of Students", typeof(string))); // do some stuff... add records etc. // A runtime error occurs here: "Cannot find column '# of Students'" var rows = dt.Select("","'# of Students' desc"); // this is just fine. rows = dt.Select("","# of Students"); How can I access this column if has special characters in its name? 回答1: You should use []

Create ADO.NET DataView showing only selected Columns

那年仲夏 提交于 2019-12-18 21:52:08
问题 In C# & .NET, can one create a DataView that includes only a proper subset of the DataColumn s 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 "projection" operation (π)? 回答1: You can't do that, but you can create a copy of the table with only the columns you want : DataView view = new DataView(table); DataTable table2 = view.ToTable("FirstColumn", "SecondColumn", "ThirdColumn"); Optionally

DataColumn Name from DataRow (not DataTable)

耗尽温柔 提交于 2019-12-18 13:52:41
问题 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 conditional processing for ease of readability. This is what I have: private void doMore(DataRow dr) { foreach (DataColumn c in dr.ItemArray) //loop through the columns. { MessageBox.Show(c.ColumnName.ToString()); } } The error returned is System

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

随声附和 提交于 2019-12-17 22:35:50
问题 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: --- Row --- Item: 1 Item: 545 Item: 507 Item: 484 Item: 501 I'd like to print the column name beside each value, as well, so that it looks like this: --- Row --- Item: 1 Hour Item: 545 Day1 KW Item: 507 Day2 KW Item: 484 Day3 KW Item: 501 Day4 KW Can

Determine if DataColumn is numeric

ぐ巨炮叔叔 提交于 2019-12-17 18:39:29
问题 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 = db.ExecuteDataSet(cmd); foreach (DataTable tbl in ds.Tables) { foreach (DataColumn col in tbl.Columns) { if (col.DataType == typeof(System.Single) || col.DataType == typeof(System.Double) || col.DataType == typeof(System.Decimal) || col.DataType == typeof

How To Change DataType of a DataColumn in a DataTable?

爱⌒轻易说出口 提交于 2019-12-17 00:40:30
问题 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 SqlDataAdapter("Select * from " + TableName, Connection); adapter.FillSchema(Table, SchemaType.Source); adapter.Fill(Table); DataColumn column = DataTable.Columns[0]; What I want to do is: Assume currently column.DataType.Name is "Double" . I want it to

Using 'SUBSTRING(expression, startIndex, length)' with BindingSource on DataColumn

非 Y 不嫁゛ 提交于 2019-12-13 20:48:09
问题 I am trying to filter a numeric string by matching the start of the source string and the length of the search string. All the filtered columns are strings. Most are just words, but there is one column that has values that look like this 001302:Alt# . The underlying data source sucks, but I cannot change the structure. The numbers are grouped based on the left-hand values (i.e. 050110 and 050534 are both related to client(05), 052123 is related to client(05) invoices(2)). My users want to be

DataColumn Expression Divide By Zero

自古美人都是妖i 提交于 2019-12-13 07:04:27
问题 I'm using basic .net DataColumns and the associated Expression property. I have an application which lets users define which columns to select from a database table. They can also add other columns which perform expressions on the data columns resulting in a custom grid of information. The problem I have is when they have a calculation column along the lines of "(C2/C3)*100" where C2 and C3 are data columns and the value for C3 is zero. The old "divide by zero" issue. The simple answer would