.net

LINQ - Left Join, Group By, and Count

Let's say I have this SQL: SELECT p.ParentId, COUNT(c.ChildId) FROM ParentTable p LEFT OUTER JOIN ChildTable c ON p.ParentId = c.ChildParentId GROUP BY p.ParentId How can I translate this into LINQ to SQL? I got stuck at the COUNT(c.ChildId), the generated SQL always seems to output COUNT(*). Here's what I got so far: from p in con...

Passing data into a callback method (via BeginInvoke) in c#

I have the following code: delegate int doStuffDel(int instanceNo, int sleepTime, int repeatCount); string result; private int doStuff(int instanceNo, int sleepTime, int repeatCount) { for (int i = 0; i < repeatCount; i++) { Console.Write(instanceNo); Thread.Sleep(sleepTime); ...

C# Regex Replace Question

if i have a string like this "Hello - World - Hello World" I want to replace the characters PRECEDING the FIRST instance of the substring " - " e.g. so replacing the above with "SUPERDOOPER" would leave: "SUPERDOOPER - World - Hello World" So far I got this: "^[^-]* - " But this INCLUDES the " - " which is wrong. how to do this wit...

How do I create an html report without hardcoding the html?

I'm currently refactoring a console application whose main responsibility is to generate a report based on values stored in the database. The way I've been creating the report up til now is as follows: const string format = "<tr><td>{0, 10}</td><td> {1}</td><td>{2, 8}</td><td>{3}</td><td>{4, -30}</td> ...

How to access the Description attribute on either a property or a const in C#?

How do you access the Description property on either a const or a property, i.e., public static class Group { [Description( "Specified parent-child relationship already exists." )] public const int ParentChildRelationshipExists = 1; [Description( "User is already a member of the group." )] public const int UserExistsIn...

Include an unknown amount of external images in a report?

I am building a report that needs to include photographs, I have no way of knowing how many photos will be taken but they are stored on a file server under folder named after the ID of the report being generated. How would I go about including these in an RDLC? ...

Update in asp.net with linq not working

hi everyone I have a strange problem. I am trying to update some fields using linq and it is not working. I tried to build the site and debug it which works and shows that the function is called. I also tried manually adding the values in the code behind file and that works too but somehow on runtime the form doesnt pass the values back...

How do you implement an interface in IronPython?

The FAQ which comes with the IronPython 2.0.1, lists the following: You can define interfaces in C#, build those into a DLL, and then implement those interfaces in Python code as well as pass the python objects that implement the interfaces to C# code. I have googled and googled and googled, but not found how to do this. Ca...

Socket Programming

In simulation of a lan-messenger in c# I am using the loopback address just for starters to check the functionality of the code.However after sending a few messages, I am getting a socket exception while using the end-connect method and then a socket exception while sending the data. Is there any reason behind this exception. privat...

Plain image in Windows Forms StatusStrip control

I'm trying to put a plain image on a System.Windows.Forms.StatusStrip control (Visual Studio 2008, C# .Net 3.5). I remember being able to do it quite easily in earlier framework versions, but for some reason the only controls made available to me from this new StatusStrip are a StatusLabel, a ProgressBar, a DropDownButton, and a SplitBu...

Binding a winforms grid to subsonic classes .Net

Hi I am trying to bind a winforms grid to a subsonic DB Generated class. I come from a ASP.Net background where this works perfectly but when i try to do this using Win Forms it never loads the data and does not allow me to edit or update. Any help would be appreciated. Thanks ...

Would a C#/.Net web browser be susceptible to exploits?

Is it correct to say that the .Net platform is more secure because the CLR guards against buffer overflow attacks? Assuming there was a web browser running in a managed OS (like Cosmos, SharpOS or Singularity), would it be technically possible for an attacker to inject IL code into the app? Would I have to worry about attacks that aren...

.NET object hydration from IDataReader slow performance

I am trying to hydrate a list of ~400 business objects and the performance becomes very slow when it needs to hydrate strings. It's taking in excess of 20secs to hydrate the 400 objects. EDIT We are using MySQL 5.1 and dotConnect for MySQL v5.0.12 as the data provider http://www.devart.com/dotconnect/mysql/ I did some benchmarks to na...

Given a private key, is it possible to derive it's public key?

From whatever little I understand by reading various material, public-private key pair are the basis of assymetric encryption and also something about choosing 2 prime numbers (which is roughly your private key) and multiplying them (which is roughly your public key), I appears that it is possible to generate a public key if you know the...

Upgrading Code from .Net 1.1 to 2.0/3.5 (C#)

I am upgrading a Windows Client application that was earlier .NET 1.1. The previous developer handwrote many solutions that can be done automatically with the newer versions of .NET. Since I am relatively fresh to .NET and do not have the complete overview of the features I am asking here. What is the most notable classes and syntax fea...

Obscure Relational Database Mapping to C# Dataset

Hi, apologies for the previous post, sometime writing the questions actually solves it too ;) as in "the answer is in the question" So I'm trying to interface an old primitive database system that is accessed vi a DLL entry point, however some work has been done on object rational mapping where one can create objects of each table and a...

Why is this appearing in my c# strings: £

I have a a string in c# initialised as follows: string strVal = "£2000"; However whenever I write this string out the following is written: £2000 It does not do this with dollars. An example bit of code I am using to write out the value: System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("/logging.txt"), strVal); I...

Why does the order affect the rounding when adding multiple doubles in C#

Consider the following C# code: double result1 = 1.0 + 1.1 + 1.2; double result2 = 1.2 + 1.0 + 1.1; if (result1 == result2) { ... } result1 should always equal result2 right? The thing is, it doesn't. result1 is 3.3 and result2 is 3.3000000000000003. The only difference is the order of the constants. I know that doubles are impl...

Opportunities to use Func<> to improve code readability

Today I finally "got" the Func<> delegate and saw how I could use it to make some of my less readable LINQ queries (hopefully) more readable. Here's a simple code sample illustrating the above, in a (very) trivial example List<int> numbers = new List<int> { 1, 5, 6, 3, 8, 7, 9, 2, 3, 4, 5, 6, }; // To get the count of those that are l...

Dropdown binding in WinForms

Imagine these two classes: class Part { public string Name { get; set;} public int Id { get; set; } } class MainClass { public Part APart { get; set;} } How can I bind MainClass to a combo box on a WinForm, so it displays Part.Name (DisplayMember = "Name";) and the selected item of the combo sets the APart property of the MainClas...