c#-2.0

How to read an .XLSX (Excel 2007) file using ADO.NET? I am finding “Could not find installable ISAM”-error

旧城冷巷雨未停 提交于 2019-12-03 15:32:52
I need to work in .net 2.0 . So I can't use OpenXML. This is my source code and I have already Installed AccessDatabaseEngine.exe . But still getting the exception: "Could not find installable ISAM". I have also tried "Extended Properties=Excel 8.0" in the connection string. static void Main(string[] args) { DataSet dataSet = new DataSet(); OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|Data Directory|\HSC.xlsx;Extended Properties=Excel 12.0;HDR=YES;"); OleDbDataAdapter dataAdapter= new OleDbDataAdapter("select * from [Sheet1$]", connection);

To check whether the string value has numeric value or not in C#

≡放荡痞女 提交于 2019-12-03 11:36:28
I am having an string like this string str = "dfdsfdsf8fdfdfd9dfdfd4" I need to check whether the string contains number by looping through the array. What about a regular expression: bool val = System.Text.RegularExpressions.Regex.IsMatch(str, @"\d"); If you are looking for an integer value you could use int.TryParse : int result; if (int.TryParse("123", out result)) { Debug.WriteLine("Valid integer: " + result); } else { Debug.WriteLine("Not a valid integer"); } For checking a decimal number, replace int.TryParse with Decimal.TryParse . Check out this blog post and comments "Why you should

Changing the row height of a datagridview

随声附和 提交于 2019-12-03 09:25:13
How can I change the row height of a DataGridView? i set the value for the property but height doesnt changed,anyother property has to be checked before set this one You need to set the Height property of the RowTemplate: var dgv = new DataGridView(); dgv.RowTemplate.Height = 30; daniele3004 You can set the row height by code dataGridView.RowTemplate.Height = 35; or by property panel Charis Try datagridview.RowTemplate.MinimumHeight = 25;//25 is height. I did that and it worked fine! you can do that on RowAdded Event : _data_grid_view.RowsAdded += new System.Windows.Forms

How to get the accurate total visitors count in ASP.NET

别来无恙 提交于 2019-12-03 09:03:02
I want to know the number of visitors online on my site. I did my research and found two solutions. Source: Code Project Online active users counter in ASP.NET It is easy to setup and easy to use but it increases the user count for every Ajax request/response too. My home page alone has 12 Ajax requests(8 requests to one page and 4 requests to another page). This dramatically increases the user count. Source: Stack Overflow Q/A Count the no of Visitors This one works exactly the same as the previous one. Source: ASP.Net Forum How to see "who is online" using C# This one looks better than the

Get Max value from List<myType>

£可爱£侵袭症+ 提交于 2019-12-03 08:04:09
问题 I have List List<MyType> , my type contains Age and RandomID Now I want to find the maximum age from this list. What is the simplest and most efficient way? 回答1: Okay, so if you don't have LINQ, you could hard-code it: public int FindMaxAge(List<MyType> list) { if (list.Count == 0) { throw new InvalidOperationException("Empty list"); } int maxAge = int.MinValue; foreach (MyType type in list) { if (type.Age > maxAge) { maxAge = type.Age; } } return maxAge; } Or you could write a more general

Detecting registry virtualization

淺唱寂寞╮ 提交于 2019-12-03 05:46:11
问题 I have a set of C# (v2) apps and I am struggling with registry virtualization in Win7 (and to a lesser extent Vista). I have a shared registry configuration area that my applications need to access in HKLM\Software\Company... Prior to Vista, everything was just written to and read from that location as needed. The code appropriately detected failures to write to that registry key and would fall back appropriately (writing to HKCU instead and notifying the user that the settings they had

How to compress files

爷,独闯天下 提交于 2019-12-03 05:06:43
问题 I want to compress a file and a directory in C#. I found some solution in Internet but they are so complex and I couldn't run them in my project. Can anybody suggest me a clear and effective solution? 回答1: You could use GZipStream in the System.IO.Compression namespace .NET 2.0. public static void CompressFile(string path) { FileStream sourceFile = File.OpenRead(path); FileStream destinationFile = File.Create(path + ".gz"); byte[] buffer = new byte[sourceFile.Length]; sourceFile.Read(buffer,

Console application not closing

一个人想着一个人 提交于 2019-12-03 05:03:01
I'm developing a console application that is supposed to run under WinCE 6.0 and WinCE 7.0 . I'm using C# , Compact Framework 2.0 for different compatibility reasons. My application is started by an external runtime called TwinCAT (from Beckhoff). Within this application, my teammate used a function block called nt_startProcess (documentation here ) that is in charge of starting my application on demand. My problem - Two different behaviors depending on the OS : When started manually (without TwinCAT) from a cmd line : My application behaves properly on both systems. It means that, the

The current identity (NT Authority/Network Service) does not have write access to

左心房为你撑大大i 提交于 2019-12-03 02:41:19
I developed a simple web application. A label and a button. On click of Button, the label will display Hello World. When I deploy this web application on my web server and access the URL, I get this error message. The current identity (NT Authority/Network Service) does not have write access to C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ I have tried the following - Navigate to C:\Windows\Microsoft.NET\Framework\v2.0.50727 and typed the following command - aspnet_regiis -ga "NT Authority\Network Service" After that also, it did not work. We checked the permissions of

How do I sort an array of custom classes?

本秂侑毒 提交于 2019-12-03 02:13:23
I have a class with 2 strings and 1 double (amount). class Donator string name string comment double amount Now I have a Array of Donators filled. How I can sort by Amount? If you implement IComparable<Donator> You can do it like this: public class Donator :IComparable<Donator> { public string name { get; set; } public string comment { get; set; } public double amount { get; set; } public int CompareTo(Donator other) { return amount.CompareTo(other.amount); } } You can then call sort on whatever you want, say: var donors = new List<Donator>(); //add donors donors.Sort(); The .Sort() calls the