.net

LinqToSql - avoiding excessive queries to the database

This scenario comes up often, now that I use LinkToSql and the classes it creates. Classic scenario - two tables: Member ID Name ... Membership ID MemberID (foreign key) Start (datetime) Expiration (datetime) ... An active membership would be one where now is between start and expiration. To find out if a user has an active members...

Registering for timer elapsed events

I want to create a class that initializes a timer which will be used as a central core for other class members to register themselves for the timer elapsed event. My problem is that I don't really know how to expose the timer elapsed event to other classes. One solution, that I think might work is that I simply expose the timer as a publ...

How to get row from dataset with sql query?

i need to take some row. They came from sql TARIH (sql column) is smalldatetime format. But give me error : DataRow[] rows = dsChart.Tables[0].Select("TARIH<='" + datestart + " " + txtStartDateTime.Text + "' and TARIH>='" + dateend + " " + txtEndDateTime.Text+"'"); Cannot perform '<=' operation on System.DateTime and System.String. ...

Why can't I edit the values in my DataGridView, even though its not set to ReadOnly?

I have a DataGridView, which is not set to ReadOnly. None of its columns are set to ReadOnly, and the object it is bound to is not set to ReadOnly. Yet, I can't edit the DataGridView items? The .DataSource property of the DataGridView is set to a ReadOnlyCollection<>, but I can programmatically alter the elements, just not from the UI...

Change Sound Volume from .net code

Is there an easy way to set the volume from managed .net code? ...

export null values to xml from a dataset

If you have a null value in a field in a dataset and export it to xml it does "remove" the field tag .. anyway to avoid this.. ...

How to get groups a group is member of in ActiveDirectory using C#?

As the title mentions I need a way to get all groups a group is member of in ActiveDirectory. To get all groups a user is member of I use public static DirectoryEntry[] GetGroupsUserIsMemberOf(DirectoryEntry directoryEntry) { ArrayList groupsUserIsMemberOf = new ArrayList(); object groups = null; ...

ASP.NET and Entity Framework in Layered Architecture - using Entity Framework for ORM only

I have an ASP.NET application that uses a layered architecture e.g. presentation layer, business logic layer, data access layer. I don't want to the business layer to have to know anything about how the data access layer is implemented and I'm not looking to bind the Entity's directly to a data control using the EntityDataSource or anyt...

Is Microsoft ressurecting Managed DirectX?

Today I saw that Microsoft announced 0.85 version of: "Windows® API Code Pack for Microsoft® .NET Framework" This pack is targeted for Windows7 OS, although most features is supposed to work under Vista. One of this pack's features is support for DirectX 11. Knowing that few years ago Microsoft stopped development of Managed DirectX,...

SELECT DISTINCT not working in .NET application, but works in SQL Mgmt Studio

I have a web app where I am calling a SELECT DISTINCT query on two joined tables. If I try to run the query from the web page, I get the following error: "The text, ntext, or image data type cannot be selected as DISTINCT". When I run it from within SQL Management Studio, the query runs fine - no error. Even more interestingly, there are...

Why does DateTime.Now.ToString("u") not work?

I currently in British summer time which is UTC +1 Hour. I confirmed my PC is correct with the following code and it returns true. System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(Date.Now) My question is then why does the UTC formatter not work as I would expect: DateTime.Now.ToString("u") It returns the exact current system d...

Using Entity Framework as Data Access Layer

In my ASP.NET application I want to implement by data acess layer using the Entity framweok so I can use it as an ORM tool. But I dont want the rest of the application to care that I'm using this or be polluted by anything entity frameowrk specific. I cant seem to find anyone who is using the entity framework exclusively in their Data a...

How can I declare and use T-SQL variables across multiple SqlCommands using the same SqlConnection object to perform multiple inserts into a table variable?

I want to load a list of records given a possibly lengthy list of usernames (anywhere from one to thousands of usernames). Disregard how the name(s) are chosen, and assume they cannot be determined from any existing data in the database. This applies to SQL Server 2005. I specifically want to avoid using a single select statement with ...

Thoughts on foreach with Enumerable.Range vs traditional for loop

In C# 3.0, I'm liking this style: // Write the numbers 1 thru 7 foreach( int index in Enumerable.Range( 1, 7 ) ) { Console.WriteLine( index ); } over the traditional for loop: // Write the numbers 1 thru 7 for( int index = 1; index <= 7; index++ ) { Console.WriteLine( index ); } Assuming 'n' is small so performance is not a...

Does unsealing a class cause a runtime or compile time break?

I am working on a project that involves a lot of immutable classes. We are interested in marking these classes as sealed, but are concerned that if we ever decide to "unseal" a class at a later time that it will cause a runtime or compile time error for the customers of our API. Is there any merit to this concern, or will unsealing a c...

Are the first 32 bits of a 160-bit SHA1 hash an acceptable substitute for a CRC32 hash?

I'm working on a .NET 3.5 project and I need a 32-bit hash value. There doesn't seem to be any methods in the .NET Cryptography classes that return a 32-bit hash (MD5 is 128 bits, SHA1 is 160 bits, etc.). I implemented a CRC32 class, but I find that the SHA1 and MD5 hashing functions that already exist are much faster. Would there be ...

Can all apps access all files in Isolated storage on shared asp.net server?

I'm considering using IsolatedStorage for my temporary files. However, the documenation seems to imply that the storage space is determiend by the windows user account, which for an ASP.NET application is NETWORK SERVICES. If there are multiple websites/applications using NETWORK SERVICES as their account, won't that mean they all will...

List of cases where USING statement should be employed

"File and Font are examples of managed types that access unmanaged resources (in this case file handles and device contexts). There are many other kinds of unmanaged resources and class library types that encapsulate them. All such types must implement the IDisposable interface. As a rule, when you use an IDisposable object, you should ...

C# WPF app crashes with System.FormatException - Corrupt .resources file

I've inherited a C# .net WPF application from a now ex-employee and am having some difficulties running the application. It all builds fine without a single error or warning, but before the GUI appears I get an error: An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Corrupt...

How to find a resource in a UserControl from a DataTemplateSelector class in WPF?

I'm creating my own UserControl and I have two different DataTemplates under the UserControl.Resources section in my XAML. I want to choose between these two datatemplates depending on the value of a property on objects displayed in a listview. I do this by creating a custom DataTemplateSelector class and overriding the SelectTemplate me...