c#-2.0

Convert array of enum values to bit-flag combination

二次信任 提交于 2019-12-22 04:15:09
问题 How to create a bit-flag combination from an array of enum values in the simplest most optimal way in C# 2.0. I have actually figured out a solution but I am just not satisfied with the complexity here. enum MyEnum { Apple = 0, Apricot = 1, Breadfruit = 2, Banana = 4 } private int ConvertToBitFlags(MyEnum[] flags) { string strFlags = string.Empty; foreach (MyEnum f in flags) { strFlags += strFlags == string.Empty ? Enum.GetName(typeof(MyEnum), f) : "," + Enum.GetName(typeof(MyEnum), f); }

External images in .rdlc data reports for winforms

孤街醉人 提交于 2019-12-21 21:59:03
问题 I searched Google for days to show images on .rdlc datareports but still not found a solution. I have set: reportViewer1.LocalReport.EnableExternalImages = true; Image properties to "External" and have set parameters value to the value property. ReportParameter Path; Path = new ReportParameter("Path", "C:\\Test\\579569.png"); this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Path }); But still i get a broken image. Is there something i am missing.I am trying this in

Get Proxy configuration before accessing an external webservice (.NET 2.0)

本秂侑毒 提交于 2019-12-21 21:40:44
问题 When trying to invoke a method on an external webservice (over the Internet) it throws me "The remote server returned an error: (407) Proxy Authentication Required." To solve this, I used the following code to set the proxy we use in the office: //Set the system proxy with valid server address or IP and port. System.Net.WebProxy pry = new System.Net.WebProxy("MyHost", 8080); //The DefaultCredentials automically get username and password. pry.Credentials = System.Net.CredentialCache

Database Logging with Enterprise Library 5

廉价感情. 提交于 2019-12-21 05:26:14
问题 Anybody knows how to implement database exception logging using EL 5.0? Thanks! 回答1: You will need to run a script against the database so that it creates a specific table structure for you. Also, there will be a stored procedure that will be created that you will have to reference in the Trace Listener's configuration section. You should be able to find this script file here: C:\EntLib41Src\Blocks\Logging\Src\DatabaseTraceListener\Scripts folder. I know this is for version 4 of the library,

Restrict multiple instances of an application

爷,独闯天下 提交于 2019-12-20 10:37:07
问题 Okay, so i've created my c# application, created an installer for it and have it working installed on my machine. The problem is, when the user opens the application exe twice, there will be two instances of the application running. I only ever want one instance of the application to be running at any time, how do I go about doing this? Thanks for your help, 回答1: The common technique for this is to create a named Mutex and check for its presence on application start. See this or this. Code

How can I convert List<string> to List<myEnumType>?

浪尽此生 提交于 2019-12-20 09:37:04
问题 I failed to convert List<string> to List<myEnumType> . I don't know why? string Val = it.Current.Value.ToString(); // works well here List<myEnumType> ValList = new List<myEnumType>(Val.Split(',')); // compile failed Of cause myEnumType type defined as string enum type as this, public enum myEnumType { strVal_1, strVal_2, strVal_3, } Is there anything wrong? Appreciated for you replies. 回答1: EDIT: Oops, I missed the C# 2 tag as well. I'll leave the other options available below, but: In C# 2,

A simple event bus for .NET [closed]

限于喜欢 提交于 2019-12-20 09:03:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I want to make a very simple event bus which will allow any client to subscribe to a particular type of event and when any publisher pushes an event on the bus using EventBus.PushEvent() method only the clients that subscribed to that particular event type will get the event. I am using C# and .NET 2.0. 回答1:

error CS0103 in ASP.NET

不打扰是莪最后的温柔 提交于 2019-12-20 06:36:38
问题 Hello when I compile a ASP.NET C# project using file Microsoft.NET\Framework\v2.0.50727\MSBuild.exe I am getting an error as "ERROR CS0103: The name (forms name) cannot be found in the current context" This error is displayed individually for every where I use ASP.NET forms. 回答1: As seen in the MSDN An attempt was made to use a name that does not exist in the class, namespace, or scope. Check the spelling of the name and check your using statements and assembly references to make sure that

how to make search of a string in a data base in c#

空扰寡人 提交于 2019-12-20 03:52:11
问题 This is the code that is used to make the search private void button1_Click(object sender, EventArgs e) { string connectionString = Tyre.Properties.Settings.Default.Database1ConnectionString; SqlConnection conn = new SqlConnection(connectionString); DataTable dt = new DataTable(); SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM table1 where Nom like " + textBox1.Text, conn); SDA.Fill(dt); dataGridView1.DataSource = dt; } and im getting this error An unhandled exception of type 'System

How do I make a TreeNode not visible? (C#)

走远了吗. 提交于 2019-12-20 01:35:10
问题 There is probably a really straightforward answer to this but I'm having difficulty finding it. Simple, I have a TreeNode and I would like to make its visibility false. (or another way of not allowing it to be shown until required). Edit - Another Question? I'm confused as to how there isn't a Visible attribute but then there is the property: Node.PrevVisibleNode; What is the difference between this and Node.PrevNode ? Thanks, 回答1: I don't think you can do that. There is an IsVisible property