datarow

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

Unable to change DataRow value

谁都会走 提交于 2019-12-17 20:41:29
问题 I want to change a Datarow value. I want to change DT2[0].ItemArray[3] I tried this code, but it didn't work. private void Func(DataRow[] DtRowTemp) { DataRow[] DT2 ; DT2 = DtRowTemp; // It work and DTRowTemp value has set to DT2 // above code don't work DT2[0].ItemArray[3] = 3; // Last Value Was 2 and I want to change this value to 3 } 回答1: With the ItemArray Property you get or set the ENTIRE array, not a single value. Use this to set the fourth item: DT2[0][3] = 3; 来源: https:/

Change a datarow item from DBNull to a string value

≡放荡痞女 提交于 2019-12-13 06:26:08
问题 I may be doing this all wrong, but here goes: OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [CRPRList$]", XLSConnect); //the XLSConnect is from a spreadsheet. I've confirmed the data is there. DataSet ds = new DataSet(); adapter.Fill(ds); DataTable thisTable = ds.Tables[0]; //The table exists and it does populate thisTable.Columns.Add("Summary"); //The new column is added and I am able to populate it (below) for (int rowNum = 0; rowNum < thisTable.Rows.Count; rowNum++) { /

Combining Datatable duplicated items with a dictionary and getting issue with duplicate datatable data

☆樱花仙子☆ 提交于 2019-12-13 05:32:05
问题 I did have another question in which I thought I was well on my way only to realize that the Dictionary is of great use, but I need to be able to really use my Datatable to loop through. The Dictionary is correctly showing the data, but my loop over the edited datatable is clearly showing both the edited and old data https://dotnetfiddle.net/6BzsYh DataTable table1 = new DataTable(); table1.Columns.Add("ID", typeof (int)); table1.Columns.Add("Weight", typeof (int)); table1.Columns.Add("Name",

Link in a DataRow (Datatable)

喜你入骨 提交于 2019-12-12 18:39:32
问题 I'm building a DataTable dynamically and I'm trying to add a "link" in the DataRow(s) that I'm adding to the DataTable. The DataTable is bound to a GridView after it's creation. Something like that : DataTable dataTable = new DataTable(); foreach (Item item in items) { DataRow row = dataTable.NewRow(); dataTable.Columns.Add(new DataColumn("col")); row["col"] = "<a href='http://www.google.com'>Link here</a>"; dataTable.Rows.Add(row); } Then I bind it to a GridView : <asp:GridView ID="grdView"

Add Columns to new DataRow

一世执手 提交于 2019-12-12 16:12:09
问题 Is it possible to create a new DataRow object and add columns to it at runtime? // How can I specify column names for this data row object? DataRow row = new DataRow(); 回答1: I don't think you can add columns to a datarow, but you certainly can to a datatable. Here's some code to do this for VB: Enum enumType StringType = 1 BooleanType = 2 DateTimeType = 3 DecimalType = 4 DoubleType = 5 IntegerType = 6 CharType = 7 End Enum Private Shared ReadOnly Property ColumnDataType(ByVal ThisDataType As

Casting DataRow to Strongly-Typed DataRow

孤者浪人 提交于 2019-12-12 05:28:21
问题 I have a class that extends DataRow : import org.jdesktop.dataset.DataRow; public class MainDataRow extends DataRow { private MainDataTable baseDataTable; protected MainDataRow(MainDataTable dt) { super(dt); this.baseDataTable = dt; } public int getId() { return (int) super.getValue(baseDataTable.getColId()); }; public void setId(int id) { super.setValue(baseDataTable.getColId(), id); }; public int getDelta() { return (int) super.getValue(baseDataTable.getColDelta()); }; public void setDelta

C# Errors when doing a simple datarow comparer

99封情书 提交于 2019-12-12 04:45:50
问题 I'm basically trying to do a custom datarow comparer, something small and to keep it simple. Basically i'm trying to compare column Mykey1 in datatableA and Mykey2 in datatableB. I'm getting three errors, and i'm not sure why they are being thrown or how to correct them. And Yes I know i'm using a for int loop and changing it to a string, but obviously this is just a lab, and yes i will be comparing strings. Here in the errors. Cannot implicitly convert type 'int' to 'string'

How to store ButtonField in a datarow where the column is set for ButtonField

落爺英雄遲暮 提交于 2019-12-12 03:47:19
问题 consider the following code protected void Button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); DataColumn dtCol = new DataColumn(); dtCol = new DataColumn("Name", typeof(string)); dt.Columns.Add(dtCol); dtCol = new DataColumn("Address", typeof(string)); dt.Columns.Add(dtCol); dtCol = new DataColumn("Account No", typeof(ButtonField)); dt.Columns.Add(dtCol); ButtonField bfname = new ButtonField { HeaderText = "Account No", DataTextField="Account No", Text = "Klik",

Convert DateTime in DataRow to a formatted date string

微笑、不失礼 提交于 2019-12-12 00:48:53
问题 I'm hoping that there is something I am not seeing clearly, but to simplify, I have the below code foreach (DataRow row in dt.Rows) { row["StartOn"] = Convert.ToDateTime(row["StartOn"].ToString()).ToString("MMM dd").ToString(); } If I run the below code I get “Aug 09” Convert.ToDateTime(row["StartOn"].ToString()).ToString("MMM dd").ToString(); If I look to see what is in row[“StartOn”] after this change it contains “8/9/2016 12:00:00 AM” I'm unable to format my DataRow to an "MMM dd" format