c#-4.0

Convert xls and xlsx to Datatable in C#

本秂侑毒 提交于 2021-02-18 12:10:29
问题 I am working in converting ths xls and xlsx to datatable in c#. I have used this code. public DataTable ReadDataExcel(string filepath) { FileStream stream = File.Open(filepath, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); excelReader.IsFirstRowAsColumnNames = true; DataSet result = excelReader.AsDataSet(); DataTable dt = new DataTable(); dt = result.Tables[0]; return dt; } In case of xls, its working fine. Whenever i used xlsx

Using a string builder, i've read a file.. How do i find if the given string is present in the file or not?

别说谁变了你拦得住时间么 提交于 2021-02-18 08:31:28
问题 I've read a file into StringBuilder. When I give a string as an input, if the word is present in the file, the output should be true.. If its not present, it should be false.. How do i do it? Could someone help me with the code? I've written the program till here.. How do i go further? Thanks alot.. :) class Program { static void Main(string[] args) { using (StreamReader Reader = new StreamReader("C://myfile2.txt")) { StringBuilder Sb = new StringBuilder(); Sb.Append(Reader.ReadToEnd()); {

How to execute each iteration of the loop in one thread with task?

主宰稳场 提交于 2021-02-17 06:53:09
问题 I have a method that check some data and I would like to know how to check this data in differents threads. I am using task and async/await pattern. private bool my myCheckMethod(List<long> paramData) { //code that check the information in the list } private void mainMethod() { //1.- get data from the data base //2.- i group the data from the database in many lists. foreach(list<List<long>> iterator in myListOfLists) { myCheckMethod(itrator); } } But I would like that the myCheckMethod not

I want to write a program that counts occurances of characters in C# [closed]

无人久伴 提交于 2021-02-17 06:43:05
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 days ago . Improve this question I want to write a program with 5 integer values/variables that will be entered by user at run-time, the program should count the number of co-occurrences of each value/total number of times each value is enter. This program is easy if written with arrays but I have to write it

Print list Object c#

China☆狼群 提交于 2021-02-15 07:52:39
问题 hi i trying print a list of object , but just name of my object class People public class Pessoa { public int ID { get; set; } public int Idade { get; set; } public string Nome { get; set; } public List<int> Setor { get; set; } } My Main class static void Main(string[] args) { List<Pessoa> pessoas = new List<Pessoa>(); pessoas.Add(new Pessoa { ID = 2, Idade = 32, Nome = "name", Setor = new List<int> { 2, 55, 32, 13, 24 } }); pessoas.Add( new Pessoa { ID = 12, Idade = 24, Nome = "name", Setor

Read an object variable having “FileInfo” object content in C# script task

廉价感情. 提交于 2021-02-11 14:53:41
问题 I'm trying to loop and read an object variable(as shown in the pic) where it has the file details(name/size/datemodified) from a share point location. Basically I need something similar to below code to just read the "Name" value. using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; using System.Data.OleDb; using System.IO; using System.Collections; using System.Collections.Generic; public void Main() { var fileinfo = Dts.Variables["User::DvarObj

ChannelFactory`1[BLLService], cannot be modified while it is in the Opening state

放肆的年华 提交于 2021-02-10 23:49:15
问题 Im in showstopper state because of an exception in WCF. The problem is that i am randomly getting this exception in windows service in WCF. Now since i cannot debug production server so i am using log4net for logging. The exception is random in time and in different functions. it Occurs few in a day with almost 400 to 1000 db entries. Now here is my proxy class code where iam checking the client open state. public static BLLServiceClient bLLServiceClient { get { if (_bLLServiceClient == null

ChannelFactory`1[BLLService], cannot be modified while it is in the Opening state

可紊 提交于 2021-02-10 23:41:06
问题 Im in showstopper state because of an exception in WCF. The problem is that i am randomly getting this exception in windows service in WCF. Now since i cannot debug production server so i am using log4net for logging. The exception is random in time and in different functions. it Occurs few in a day with almost 400 to 1000 db entries. Now here is my proxy class code where iam checking the client open state. public static BLLServiceClient bLLServiceClient { get { if (_bLLServiceClient == null

How to stop function once message box displayed

雨燕双飞 提交于 2021-02-10 23:19:42
问题 public void CreateFileOutput(object parameter) { TransactFileCreation(); WPFMessageBox.Show("test", "Process completed successfully."); } public void TransactFileCreation() { if (BatchFolderPath == null) { WPFMessageBox.Show("test", "Select a Batch folder"); return; } // code.. } I am calling TransactFileCreation() from CreateFileOutput(). Once Msg Box displayed, further the function should not work. But in my case, it again go to the main function and displaying msg box present in that. How

How to stop function once message box displayed

对着背影说爱祢 提交于 2021-02-10 23:18:01
问题 public void CreateFileOutput(object parameter) { TransactFileCreation(); WPFMessageBox.Show("test", "Process completed successfully."); } public void TransactFileCreation() { if (BatchFolderPath == null) { WPFMessageBox.Show("test", "Select a Batch folder"); return; } // code.. } I am calling TransactFileCreation() from CreateFileOutput(). Once Msg Box displayed, further the function should not work. But in my case, it again go to the main function and displaying msg box present in that. How