.net

Comma issue when exporting DataTable to CSV

痞子三分冷 提交于 2021-02-07 20:18:41
问题 I've adopted some code which converts a DataTable into a CSV file. It seems to work well, except for when commas are used in the actual data. Is there a way to display the comma in that case? This is what I've done: StringBuilder sb = new StringBuilder(); IEnumerable<string> columnNames = dtResults.Columns .Cast<DataColumn>() .Select(column => column.ColumnName); sb.AppendLine(string.Join(",", columnNames)); foreach (DataRow row in dtResults.Rows) { IEnumerable<string> fields = row.ItemArray

ManualResetEvent WaitOne(timeout) returns early. Any ideas why?

房东的猫 提交于 2021-02-07 20:18:10
问题 I'm using the ManualResetEvent WaitOne(timeout) method and set the timeout value to 30ms. I log using log4net at either side of the WaitOne. The log messages show the WaitOne returned false after only waiting for 22ms. What would cause this? A .Net bug? Thanks in advance. 回答1: From the Win32 documentation on Wait Functions which the .NET methods ultimately use (http://msdn.microsoft.com/en-us/library/ms687069.aspx): Wait Functions and Time-out Intervals The accuracy of the specified time-out

Remove spaces only before and after commas

♀尐吖头ヾ 提交于 2021-02-07 20:13:32
问题 I am looking for a regex (?) way to remove spaces before and after commas only. Example: ((100 0, 101 0, 101 1, 100 1, 100 0) , (100.2 0.2, 100.8 0.2, 100.8 0.8, 100.2 0.8, 100.2 0.2)) Expected result: ((100 0,101 0,101 1,100 1,100 0),(100.2 0.2,100.8 0.2,100.8 0.8,100.2 0.8,100.2 0.2)) I could not yet find a satisfactory answer despite numerous searches. 回答1: You can use the following regex: s = Regex.Replace(s, " *, *", ","); This searches for every comma preceded and/or followed by any

Different versions of Crystal Reports runtime

醉酒当歌 提交于 2021-02-07 20:01:42
问题 I have two WinForm applications that use CR runtime to generate reprts.When CR runtime 13.20 is installed, the newer application will complain that it can't find and load CR 13.21 (13.0.350) assembly. If I upgrade CR runtime to 13.21 (13.0.350) that new application will work but the older one errors out with exception stating that it can't find and load CR runtime assembly 13.20 (13.0.200). All workstations operate on CR runtime 13.20 so how can I make new app created in VS2015 with CR 13.21

Different versions of Crystal Reports runtime

家住魔仙堡 提交于 2021-02-07 20:01:27
问题 I have two WinForm applications that use CR runtime to generate reprts.When CR runtime 13.20 is installed, the newer application will complain that it can't find and load CR 13.21 (13.0.350) assembly. If I upgrade CR runtime to 13.21 (13.0.350) that new application will work but the older one errors out with exception stating that it can't find and load CR runtime assembly 13.20 (13.0.200). All workstations operate on CR runtime 13.20 so how can I make new app created in VS2015 with CR 13.21

How to set a column in gridview as hyperlink which is autogenerated

吃可爱长大的小学妹 提交于 2021-02-07 19:51:05
问题 I want to make the gridview.columns[0] as hyperlink. I tried so many work around mentioned in different sites. I am binding a list<> to the grid. and I need to make the first column as hyperlink and upon clicking that link, it should be redirected to a page with the corresponding item. Which event I need to use and how can I pass that value from the list? 回答1: void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var firstCell

How to set a column in gridview as hyperlink which is autogenerated

北战南征 提交于 2021-02-07 19:47:13
问题 I want to make the gridview.columns[0] as hyperlink. I tried so many work around mentioned in different sites. I am binding a list<> to the grid. and I need to make the first column as hyperlink and upon clicking that link, it should be redirected to a page with the corresponding item. Which event I need to use and how can I pass that value from the list? 回答1: void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var firstCell

CoInitializeSecurity throws RPC_E_TOO_LATE in Visual Studio 2017

◇◆丶佛笑我妖孽 提交于 2021-02-07 19:43:35
问题 I'm trying to run an application making a call to CoInitializeSecurity at startup. This works in Visual Studio 2013, but does not work in Visual Studio 2017 - and I'm curious to why this is. When calling CoInitializeSecurity at startup in Visual Studio 2017 I get a COMException with the error code RPC_E_TOO_LATE (0x80010119) which indicates a call has already been made to CoInitialize , this does not happen in Visual Studio 2013. I have seen this behaviour before in Visual Studio 2013 when

.NET Core - Globalization and Localization - Class library

假装没事ソ 提交于 2021-02-07 19:42:24
问题 Following this documentation on how to implement globalization and localization using .NET Core, my goal is to store all my resources in a single global resource file located in a different project, (class library). Project 1 - Startup.cs public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName

How to define DateTime parse format for general date format with optional time part?

佐手、 提交于 2021-02-07 19:39:39
问题 What is the right DateTime format to parse a date from string in general date format ("G") with optional time part ("d") ? I can have two types of dates: "12/13/2012 6:30:00 PM" "3/29/2013" How to parse them in unified way? Right now I'm trying to parse with "G" format and then if it not parsed with "d" format. 回答1: If your CurrentCulture supports MM/dd/yyyy h:mm:ss tt (I assume your LongTimePattern has h ) and M/dd/yyyy (I assume your ShortDatePattern has M ) as standard date and time format