.NET

There are 11 entries for the tag .NET

How to split SQL file by GO statement

In some situations when using scripts to create/update database in code, I had to split input SQL script file by GO statements, as SqlCommand doesn’t really understand it. But in some place, I’ve came to a strange-looking code that does exactly that but… in really weird and NOT correct way. So here we go. How NOT to write: //separator char not used in TSQL char ch = '^';   //Ed: str is the text from SQL batch file ...

Setting property by name with automatic type conversion

I liked the idea of binding to properties in WPF or Workflows. So implemented something similar (although less powerful) in my code: I had a list of tasks and their data context, so I needed somehow to “bind” data from context to properties of tasks. As a part of implementation, I have created a method that allowed me to take an object (task), take one of its properties by name and assign that property a value. Everything in reflection, since property name nor its value is not known at design time and only evaluated at runtime. Remembering that my value is...

Visual Studio 2008 template for Prototype console application

There have been several occurrences where I needed to have something quick UI, to check some set of classes. Building a whole Windows Forms or WPF application seemed to be overkill, specially when I will not be responsible for building UI later, or application will not need UI at all. So what we usually do? Right, create a command line utility, than another one and another one.. Most of them look exactly the same. So some time ago I have created a Visual Studio project template, that will contain all I need in such console applications, and all...

Access Violation in DsBrowseForContainer on Windows Vista. The code

Since my post about DsBrowseForContainer problem in Vista, I have been asked several times to provide the code on solution. So here we go – below is the class that I use to browse for OU container, it is written to .NET 3.5, but can be easily adapted to earlier versions as well: public sealed class OUPickerDialog{ public OUPickerDialog() { Caption = "The container picker"; Title = "Select a container:"; } #region Imports ...

Progress bar in Janus Grid

Janus's Grid doesn't allow custom controls inside its cells, but for my task, I had to show a progress bar on each row and was looking on how to do that. Well, I couldn't find any info apart from drawing the progress myself. Fortunately, progress bar is a simple rectangle and drawing rectangle is quite simple task. Below I'll explain how I did it. You can also download a zip file, containing sample project (you will have to have Janus GridEx installed on your system in order to be able to compile it though) - see the...

ADO.NET Entity Framework, SQLCE and identity columns

Recently I've doing some works using MS SQL Compact Edition and for data layer ADO.NET Entity Framework was chosen. Now MS only recently added support for SQLCE in the framework, so its kind of beta inside beta. Some features are not working properly or missing, as for example, support for identity columns. While SQLCE provides support for auto-generated columns, the framework doesn't yet have it. And of course all my IDs in tables are auto-generated integer values, e.g. identity. Of course the only option was to generate ID at client. But I didn't want to change everything to be GUID,...

WPF: Adding text as a background of TextBox or ComboBox

One of those small things I liked in Vista is help text in the background of various text boxes, such as Search in Explorer: When you click on it, the text disappears, leave it without typing anything, you again see the text. In many places this might be a useful thing - it helps user to determine what should be written inside and there is no additional place needed to put the label. So I wanted to figure out how to do this in pure XAML without any additional code. It turned out this was pretty...

LINQ to Entities and SQL Compact Edition

If you want to use LINQ to Entities (AKA ADO.NET Entity Framework) with your SQL CE database, download and install SQL CE SP1 Beta (see link below). Uninstall SQL Compact Edition 3.5 that you have right now, but leave Design Tools. And then install those 2 files downloaded from MS Downloads Center. Here is the link: http://www.microsoft.com/downloads/details.aspx?FamilyID=68539FAE-CF03-4C3B-AEDA-769CC205FE5F&displaylang=en Technorati Tags: LINQ, ADO.NET, .NET, SQLCE

Running .NET Windows service project from debugger

It sounds like an easy task, but I have seen many times that people actually do some strange stuff, trying to run a .NET project containing Windows service from debugger. So decided I'll write a small note on how do I do that. If you create a project for Windows service, using wizard in Visual Studio, try to execute it straight from debugger. You'll get that service cannot start or something similar. I do a small trick by checking if debugger is attached and calling some sort of Start method in such case, or executing code created by wizard otherwise....

Access Violation in DsBrowseForContainer on Windows Vista

I have used the example from SDK for browsing Active Directory (can be found here) and in Vista the method DsBrowseForContainer throws AccessViolationException in .NET. While testing, I have created a new MFC (C++) project and added a code for calling to DsBrowseForContainerW (similar to above). That worked perfectly, which means the problem is not in Vista, rather in .NET or marshalling in .NET. Checking the structure returned from the function call, I have found that previously NULL "pszRoot" member is now filled in! Means DsBrowseForContainerW has allocated a memory for it and passed back to me. Looks like marshaller...

Loading WPF TreeView dynamically

In WinForms, I used to catch BeforeExpand event of tree view and add additional items on the fly, from database (or any other source of course). So was looking to do the same thing in WPF TreeView and somehow missed the Expanded event of TreeViewItem. You can subscribe to this event in XAML like this: <TreeView TreeViewItem.Expanded="TreeView_Expanded"></TreeView> The rest of code is pretty simple, but if you want to see a full example, look at this post in MSDN forums: Loading TreeView nodes on demand. Technorati Tags: WPF, .NET