.net-2.0
Using DateTime in a SqlParameter for Stored Procedure, format error
How are you setting up the SqlParameter? You should set the SqlDbType property to SqlDbType.DateTime and then pass the DateTime directly to the parameter (do NOT convert to a string, you are asking for a bunch of problems then). You should be able to get the value into the DB. If not, here is a … Read more
What are alternative ways to suspend and resume a thread?
You’ll want to use an AutoResetEvent EventWaitHandle. Say you want to do something like this (NOTE: don’t do this!): private Thread myThread; private void WorkerThread() { myThread = Thread.CurrentThread; while (true) { myThread.Suspend(); //Do work. } } public void StartWorking() { myThread.Resume(); } Like others have said, this is a bad idea. Even though only … Read more
How do I select all items in a listbox on checkbox checked?
The fact is that ListBox.Items is a plain object collection and returns plain untyped objects, which cannot be multi-selected (by default). If you want to multi-select all items, then this will work: for (int i = 0; i < myListBox.Items.Count;i++) { myListBox.SetSelected(i, true); }
Load vs. Shown events in Windows Forms
Avoid using MessageBox.Show() to debug this. It pumps a message loop, disturbing the normal flow of events. The Load event is triggered by Windows sending the WM_SHOWWINDOW message, just before the window becomes visible. There is no Windows notification for “your window is now fully shown”, so the WF designers came up with a trick … Read more
Best method to obfuscate or secure .Net assemblies [closed]
This is a pretty good list of obfuscators from Visual Studio Marketplace Obfuscators ArmDot Crypto Obfuscator Demeanor for .NET DeployLX CodeVeil Dotfuscator .NET Obfuscator Semantic Designs: C# Source Code Obfuscator Smartassembly Spices.Net Xenocode Postbuild 2006 .NET Reactor I have not observed any performance issues when obfuscating my code. If your just sending text basted stack … Read more
How to show text in combobox when no item selected?
Use the insert method of the combobox to insert the “Please select item” in to 0 index, comboBox1.Items.Insert(0, “Please select any value”); and add all the items to the combobox after the first index. In the form load set comboBox1.SelectedIndex = 0; EDIT: In form load write the text in to the comboBox1.Text by hardcoding … Read more
What is the best way to store pairs of strings, make an object or use a class in .NET?
The “pair” generic class for .NET is Tuple. You would use it like: var strings=new List<Tuple<string, string>>(); strings.Add(Tuple.Create(“REFERENCE”, “Ref”)); A dictionary is a perfectly acceptable substitute if the left-most string is unique (ie a key). You’ll get errors otherwise. As to whether it’s better to use the built-in collections or create an actual object, depends … Read more
System.ValueType Understanding
ValueType is a little white lie. The built-in numeric types (int, long, byte), char, enums and structs are all value types. This means that they have a different concepts of identity and equivalence to object types. If I do x = y and x and y are reference types, then x and y now point … Read more
Strange Error – CS0012: The type x is defined in an assembly that is not referenced
I’m Mike’s coworker, and we worked out a solution. The type X is defined in his assembly, that is only in the GAC. Even though his ASP.NET web appplication did have a reference, it was failing to load from the GAC only for this UserControl. The rest of the application worked as expected. We confirmed … Read more