Posted by

Comments

# re: Welcome to Deborah’s Developer MindScape

Thursday, July 02, 2009 8:15 PM by Beth Massi

Welcome to the blogsphere, Deborah! Can't wait to read what you got. I also love how you picked up my tag line for the signoff for your posts....

"Enjoy!" ;-)

# re: Welcome to Deborah’s Developer MindScape

Thursday, July 02, 2009 8:16 PM by Beth Massi

Oh and one more thing... HAVE FUN!!

-B

# XML Literals: Creating an XML File

Friday, July 03, 2009 10:27 AM by Deborah's Developer MindScape

One of my favorite features in VB 9 (Visual Studio 2008) is XML Literals. This example demonstrates how

# Lambdas: Aggregating Strings

Friday, July 03, 2009 12:24 PM by Deborah's Developer MindScape

Looping through a list to append strings is often more challenging than it should be. For example… In

# re: Lambdas: Aggregating Strings

Friday, July 03, 2009 12:54 PM by Shawn Wildermuth

The other problem here is that the aggregation of the strings is cool, but the string + string approach involves creation of a lot of strings for the GC to clear.  You should be usng a StringBuilder.  This is very inefficient on a large number of strings:

string final = "";

for (var x = 0; x < 10; ++x)

{

 final += x.ToString();

}

This simple code (like your aggregation) will create about 30 strings that aren't used.  Being mindful of the immutability of strings is important.

# re: Welcome to Deborah’s Developer MindScape

Friday, July 03, 2009 6:49 PM by Bill Booth

Like what I see so far, subscribed!

# re: Lambdas: Aggregating Strings

Saturday, July 04, 2009 10:03 PM by Jonathan

I prefer using string.join to accomplish these kinds of things -- the only downside is that it needs a string[].  Luckily, LINQ includes ToArray() to turn the IEnumerable<string> that comes out of Select into a string[].

string email = string.join("; ",custList.Select(c => c.EmailAddress).ToArray());

# Lamdas

Monday, July 06, 2009 10:24 AM by Greg

It's easier to visualy inspect and verify that the for loop exmple works than the lambda based one.

# re: Welcome to Deborah’s Developer MindScape

Monday, July 06, 2009 11:34 AM by Bob Mercier

I'm glad to see you blogging. I am trying to subscribed to the Rss for post feed but my reader (Omea) epps giving me a 'cookie header' error. You may want to check on this.

# re: Lambdas: Aggregating Strings

Monday, July 06, 2009 12:39 PM by Deborah Kurata

Hey Shawn -

Thanks for stopping by my blog.

Yes, just because you can do something does not necessarily mean that you should. Have you seen the scuba diving cat? :-)

www.youtube.com/watch

As developers, we always have to evaluate techniques for "fitness of purpose". We have to decide whether a specific technique is appropriate for what our application needs to achieve.

This technique may be fine for an application that will have 1 to 5 email addresses. But it would not work well for a spamming app sending to hundreds of email addresses.

Thanks for your thoughts!

# re: Lambdas: Aggregating Strings

Monday, July 06, 2009 12:46 PM by Deborah Kurata

Hi Jonathan -

Thanks for your suggestion.

It appears that Join is smarter and does not create the excess strings that the Aggregate method creates.

Cool! Thanks again!

# MasterMind: MasterMind Class

Monday, July 06, 2009 3:00 PM by Deborah's Developer MindScape

This entry describes the MasterMind class from this example in further detail: Public Class MasterMind

# MasterMind: Peg Class

Monday, July 06, 2009 3:07 PM by Deborah's Developer MindScape

This entry describes the Peg class from this example in further detail: Public Class MasterMind End Class

# re: Welcome to Deborah’s Developer MindScape

Monday, July 06, 2009 6:04 PM by Stephen Patten

Thank you!

I'm working through this months examples as we speak... sort of..

# DAL: Data Access Layer

Tuesday, July 07, 2009 5:11 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# DAL: Data Access Layer

Tuesday, July 07, 2009 5:28 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# DAL: Retrieve a DataTable using a SQL Statement

Tuesday, July 07, 2009 6:04 PM by Deborah's Developer MindScape

This post provides an implementation of a method that retrieves a DataTable from a SQL Server database

# re: DAL: Retrieve a DataTable using a Stored Procedure

Wednesday, July 08, 2009 7:14 AM by Jack Dolby

Deborah, could you do a post on creating/maintaining SPs, including when one should lean toward a SP versus a dotnet query?

TIA,

jack

# re: General: Brazil (the Movie)

Wednesday, July 08, 2009 11:51 AM by Beth Massi

I LOVE that movie!!! Braaaazzzziiiiillllll. I suppose you wouldn't like Woody Allen's "Sleeper" either then. Another great comedy about the future. ;-)

# DAL: Retrieve a DataTable using a Stored Procedure

Wednesday, July 08, 2009 12:23 PM by Deborah's Developer MindScape

This post provides an implementation of a method that retrieves a DataTable from a SQL Server database

# re: DAL: Retrieve a DataTable using a Stored Procedure

Wednesday, July 08, 2009 12:25 PM by Deborah Kurata

Hi Jack -

I just posted this:

msmvps.com/.../dal-using-stored-procedures.aspx

Hope it provides the information you are looking for.

# re: General: Brazil (the Movie)

Wednesday, July 08, 2009 12:49 PM by Deborah Kurata

Hey Beth -

Someone told me that I just didn't *get* the British humor in this movie. But I am a big Dr. Who, Torchwood, Graham Norton, and Top Gear fan, and used to watch Monty Python. So that can't be it. :-)

This movie was written by some of the same people that wrote Monty Python and some of the same actors were in this movie.

# XML Literals: Reading an XML File

Wednesday, July 08, 2009 4:28 PM by Deborah's Developer MindScape

In a prior post here , I created an XML file using VB 9 (Visual Basic 2008/.NET Framework 3.5). This

# XML Literals: Reading an XML File

Wednesday, July 08, 2009 4:31 PM by Deborah's Developer MindScape

In a prior post here , I created an XML file using VB 9 (Visual Basic 2008/.NET Framework 3.5). This

# re: DAL: Using Stored Procedures

Thursday, July 09, 2009 8:18 AM by Jack Dolby

Deborah, that was great! Exactly what I needed.

You have a talent for putting descriptions into UNDERSTANDABLE language.

Much appreciated.

jack

# DAL: Access a DataReader using a Stored Procedure

Thursday, July 09, 2009 12:57 PM by Deborah's Developer MindScape

This post provides an implementation of a method that accesses a DataReader using a stored procedure

# DAL: Data Access Layer

Thursday, July 09, 2009 12:58 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# DAL: Access a DataReader using a SQL Statement

Thursday, July 09, 2009 2:03 PM by Deborah's Developer MindScape

This post provides an implementation of a method that accesses a DataReader from a SQL Server database

# DAL: Data Access Layer

Thursday, July 09, 2009 2:05 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# re: EastBay.NET Rocks!

Friday, July 10, 2009 10:54 AM by Beth Massi

Thanks Deborah!

I took the Co/ContraVariance example from Lucian's blog. Glad I could explain it in "human"-ish terms ;-)

blogs.msdn.com/.../co-and-contra-variance-how-do-i-convert-a-list-of-apple-into-a-list-of-fruit.aspx

Enjoy!

# Populating a Business Object from a DataTable

Friday, July 10, 2009 3:43 PM by Deborah's Developer MindScape

Most business applications have business objects such as customer, order, or invoice. Often, the data

# Populating a Business Object from a DataTable

Friday, July 10, 2009 4:12 PM by Deborah's Developer MindScape

Most business applications have business objects such as customer, order, or invoice. Often, the data

# re: Enum: Binding to the Description Attribute

Saturday, July 11, 2009 2:49 PM by paul

Great !

How using this in a multi-language context?

# re: Enum: Binding to the Description Attribute

Sunday, July 12, 2009 6:47 AM by Moggoly

I wrote about this same solution over a year ago - with a slight difference in that my solution is using a generic extension method to get the description attribute value.

# Daily tech links for .net and related technologies - July 9-13, 2009

Monday, July 13, 2009 3:15 AM by Sanjeev Agarwal

Daily tech links for .net and related technologies - July 9-13, 2009 Web Development Using Custom T4

# re: Enum: Binding to the Description Attribute

Monday, July 13, 2009 12:15 PM by Deborah Kurata

Hi Moggoly -

Thank you for your post. My extension method just extended [Enum]. It would be interesting to see how you did it with a generic extension method. Would you be willing to post some of your code?

Thanks again!

# re: DAL: Access a DataReader using a Stored Procedure

Tuesday, July 14, 2009 1:36 PM by Nisus

You forgot to close the reader.

CommandBehavior.CloseConnection means that underlying connection will be closed during the closing of the reader.

So using statement or simple call for reader.Close(); should do the trick

using (SqlDataReader reader = Dac.ExecuteDataReader("CustomerRetrieveAll", null))

{

   while (reader.Read())

   {

       // Do something with the data

   }

}

If not doing so you connection pool will reach it's limir very quickly, especially in a web application.

# re: DAL: Access a DataReader using a Stored Procedure

Tuesday, July 14, 2009 3:20 PM by Deborah Kurata

Nisus -

Yes, you are correct! I had a Close statement in my sample code but neglected to copy it to my post.  But a using statement is event better.

I'll edit my example per your suggestion.

Thanks!

# Dates: Binding to Day Numbers

Tuesday, July 14, 2009 4:07 PM by Deborah's Developer MindScape

My prior post demonstrated how to bind to a list of month names. Once the user picks the desired month

# re: Debugging: Heisenbug

Tuesday, July 14, 2009 5:55 PM by Mark Wisecarver

Don't have one to post but wanted to say this is a great topic. Also want to say thanks for all your recent articles, especially for posting C# and VB code each time, very nice.

# re: Enum: Binding to the Description Attribute

Thursday, July 16, 2009 7:57 AM by Yann

Hi Deborah,

Thanks, this was just what I needed!

However, instead of using a dictionary as you did, I used LINQ with an anonymous type.

           Dim enums = [Enum].GetValues(_type)

           result = _

               ( _

                   From e As Object In enums _

                   Select e = New With _

                       { _

                             .ID = CInt(e) _

                           , .Name = CType(e, [Enum]).GetDescription _

                       } _

                   Order By _

                       e.Name _

               ).ToList

I had already created an extension method "ToWords" for the string type (which I didn't show here for simplicity), but I needed to have "Week 1/2", "Week 3/4" which of course I couldn't have as enum members.

So your code helped me out enormously!

Thanks,

Yann

# re: Enum: Binding to the Description Attribute

Thursday, July 16, 2009 6:19 PM by Deborah Kurata

Very cool, Yann.

Thanks!

# re: XML Literals: Creating an XML File

Friday, July 17, 2009 1:59 AM by Miller_a

Hi Deborah,

I was directed here by you to look at this, does this work on .net framework 2.0 with visual studo 2005?

# re: XML Literals: Creating an XML File

Friday, July 17, 2009 10:36 AM by Deborah Kurata

Hi Miller -

No. As it states at the top of the post, this is for Visual Studio 2008, .NET Framework 3.5.

(Guess I should have asked that before linking you to this page.)

# Formatting Text Files

Tuesday, July 21, 2009 3:16 PM by Deborah's Developer MindScape

There are often times that you need to write out text files containing data managed by your application

# Formatting Text Files

Tuesday, July 21, 2009 3:16 PM by Deborah's Developer MindScape

There are often times that you need to write out text files containing data managed by your application

# re: Enum: Binding to the Description Attribute

Tuesday, July 21, 2009 5:14 PM by Deborah Kurata

Hi Paul -

If you have to support multiple languages in your UI, you should not have any strings that you plan to display to the user hard-coded in the code.

So you won't be able to leverage this technique.

# re: Building a Business Object Base Class

Wednesday, July 22, 2009 3:12 PM by mendicant

Typical MS tightly coupled approach. You're going to be writing a TON of data access for each object. Use NHibernate and you can have state AND persistence solved out of the box.

And if the ActiveRecord pattern is really what you want, there's persistence frameworks for that too.

Even in the .Net world, we are so far beyond ever having to write all this code manually. This is solving a problem that has already been solved.

# re: Building a Business Object Base Class

Wednesday, July 22, 2009 4:06 PM by Deborah Kurata

Hi mendicant -

Thanks for coming by the blog. The purpose of putting this into a base class is so you never have to write it again.

And I have additional methods (not shown here) that automatically populate my business objects and update the database based on the business object properties. So I don't write any data access for any objects.

I only need the stored procedures, and I have written a code generator to do that for me. :-)

# re: Building a Business Object Base Class

Wednesday, July 22, 2009 4:18 PM by Mark

... and with Spring.Net, AOP, etc.

I used to try to this in VB. The overhead was just not worth the effort.  At most, implement the property change listeners and use a service oriented architecture.

# re: Building a Business Object Base Class

Wednesday, July 22, 2009 5:10 PM by mendicant

Hi Deborah,

Your base class provides:

public abstract Boolean SaveItem();

Which means every item needs to override it. Now I've got to write code in every single class that implements it. Do your automatic methods exist on each item?

As for the stored procs, I'm not ready to even begin down that road again.

Thanks for taking my first comment so nicely, I wasn't very rational when I wrote it.

# re: VB or C#?

Wednesday, July 22, 2009 7:25 PM by Tim Murphy

Great post. Can you provide specifics for comment " I have found some things that I much prefer doing in C#".

I'm a vb.net programmer (history in Access rather than VB) and besides more code/examples on the net being C# I struggle to find where/why C# is preferable. I had to write about 30 lines of C# the other day and found it a giant pain in the butt. All those curly braces and semi colons just seem totally ridiculous.

# re: Building a Business Object Base Class

Wednesday, July 22, 2009 7:34 PM by Mark

Deborah, You will still need "Data access" code even with Stored Procs. Do you mean that is common code?

I am with mendicant  on SPs. I'll try not to get started on them too. :)

# re: Building a Business Object Base Class

Wednesday, July 22, 2009 10:06 PM by Harry

+1 to mendicant for acknowledging the harsh tone in the comment

+1 to Deborah for trying so hard to come up with this even people say the problem has been solved. So what, next time when you actually need to use NHibernate you are that much wiser than those who didn't try

-1 to me for not providing any value in this comment ....

# re: Populating a TreeView Control from XML

Thursday, July 23, 2009 10:51 AM by Star79

Get the following errors from the code:

Error 1 The best overloaded method match for 'System.Web.UI.WebControls.TreeNodeCollection.Add(System.Web.UI.WebControls.TreeNode)' has some invalid arguments C:\web_projects\AM\MasterPage.master.cs 29 29 C:\web_projects\AM\

Error 2 Argument '1': cannot convert from 'string' to 'System.Web.UI.WebControls.TreeNode' C:\web_projects\AM\MasterPage.master.cs 29 52 C:\web_projects\AM\

Error 3 'System.Xml.Linq.Extensions.Nodes<T>(System.Collections.Generic.IEnumerable<T>)' is a 'method', which is not valid in the given context C:\web_projects\AM\MasterPage.master.cs 32 43 C:\web_projects\AM\

# re: VB or C#?

Thursday, July 23, 2009 12:32 PM by Deborah Kurata

Hi Tim -

Thank you for coming by the blog.

These are a few right off the top of my head...

VB: Dim tb As TextBox = DirectCast(sender, TextBox)

C#: TextBox tb = (TextBox)sender;

VB: Dim sampleString As String

C#: string sampleString;

VB: AddHandler SampleUserControl1.ValueChanged, _

      AddressOf SampleUserControl1_ValueChanged

C#: sampleUserControl1.ValueChanged +=

       sampleUserControl1_ValueChanged;

VB:

   Private _FirstName As String

   Public Property FirstName() As String

       Get

           Return _FirstName

       End Get

       Set(ByVal value As String)

           _FirstName = value

       End Set

   End Property

C#: public string LastName { get; set; }

[VB will be getting automatically implemented properties in VS 2010]

# re: Populating a TreeView Control from XML

Thursday, July 23, 2009 12:42 PM by Deborah Kurata

Hi Star79 -

Thank you for stopping by the blog. It looks like from your errors you are using a WebForms TreeView?

This code is for a WinForms TreeView as per the first line of the post.

You can use the same general concept for accessing the XML, but you would need to change the code to add nodes to the WebForms TreeView to the correct ASP.NET syntax.

# re: Building a Business Object Base Class

Thursday, July 23, 2009 12:54 PM by Deborah Kurata

Hi mendicant -

In the simple sample code I have posted on my Web site, I do indeed have the SaveItem code manually written into each business object. (But in my sample code, there is only one business object so not a big deal.)

In my *real* applications, I have some code in my base class (not shown here) that automatically populates the stored procedure parameters. So the SaveItem method in each business object only needs to define the appropriate stored procedure and reset the entity state.

I have also worked with some very basic Linq to SQL with POCO. I plan to do a post on that soon.

# re: Populating a TreeView Control from XML

Thursday, July 23, 2009 1:01 PM by Star79

Hi Thanks for pointing that out...Iam totally new to LINQ can you pls guide me on this..

Thanks,

appreciate your blog.

# re: VB or C#?

Thursday, July 23, 2009 6:09 PM by Tim Murphy

Thanks for the reply. Personally I see only the last 2 items as a benefit although as you said VS 2010 will remove the last benefit.

No doubt often the VB version is more verbose but I find more often than not the verboseness (if there is such a word) is easier to read and more natural.

As you said it comes down to choice and where your roots in development started. As I started with dBase I'm use to languages of the 4GL nature as opposed to C# being 3GL.

I really appreciate reading a blog that has VB & C# code. Keep up the good work.

# re: Writing Data from a DataTable to Excel

Thursday, July 23, 2009 6:13 PM by Mark Wisecarver

Awesome. Whatever we can do to keep you rolling please do...You're kicking this stuff out at an unbelievable rate and it's all uber cool. Thanks!

# re: Building a Business Object Base Class

Friday, July 24, 2009 2:08 AM by Julian

Hi Deborah

Your real application version base class sounds interesting could you show an example.

Julian

# Interesting Finds: July 24, 2009

Friday, July 24, 2009 6:11 AM by Jason Haley

Interesting Finds: July 24, 2009

# re: Formatting Text Files

Friday, July 24, 2009 3:34 PM by Keith Goodyear

Very informative and simple program that was a big help for something I've needed to learn.  Thank you.

# re: Doctor Who

Friday, July 24, 2009 4:53 PM by Dave Noderer

I worked for Prime Computer and helped design these computers that Tom Baker and assistant made an ad for in the late early 80's:

www.facebook.com/.../share.php

# re: Doctor Who

Friday, July 24, 2009 5:37 PM by HoyaSaxa93

One word for Dr. Who... BRILLIANT!

# re: Doctor Who

Saturday, July 25, 2009 9:59 AM by Rhonda Tipton

Now that is my kind of vacation. I love Dr. Who!

# VB.NETからExcelを操作する時参考になるサイトまとめ

Sunday, July 26, 2009 4:41 AM by 戦艦ゆにっき

業務でツールが出力したデータを分析して結果をExcelに出力するアプリを作っています。 本当、このアプリ開発にはいろいろあり悩まされてきたけど、ようやく終わりが見えてきたところで困ったのがExcelの終了処理

# re: Doctor Who

Monday, July 27, 2009 8:39 AM by Mike Rissen

I question both the character and caliber of any developer who DOESN'T love Dr Who.

I'd LOVE to go there.  That would be so awesome...

# re: Doctor Who

Monday, July 27, 2009 11:28 AM by Deborah Kurata

Hi Dave -

Oh ... those are so funny! Thanks for sharing!

# re: Finding Controls on Forms

Monday, July 27, 2009 7:33 PM by James Arendt

Debora, your articles hit that sweet spot for those looking at "how to do stuff" with .NET. Straight to the point, easy to understand. Having examples in both VB and C# is also a rarity and greatly appreciated.

The C# code example in this article could be improved, though. If you're using GetType() and typeof, there's no need to then do a .Name to do the comparison. You can use the == operator to do a direct comparison between the two type objects.

With that said, I personally would probably use the is or as operator in C# for the check unless I only wanted TextBox objects. Those operators will match a TextBox or anything that derives from TextBox. The comparison with GetType and typeof will only match a TextBox object.

Lastly, if the code is intended to work with any type of "textbox" (ex. TextBox, MaskedTextBox) in the processing, keying off of the TextBoxBase class would allow that.

# re: User Control Events in VB and C#

Tuesday, July 28, 2009 4:26 AM by Gilbert

Hi Deborah,

Thank you for taking the time to put this beautiful article. Im newbie in C# and this is just what I was looking for, exactly something like this.

After one day of trying without any success, I found I made two slight omissions, that the article not mention about these.

1. You need to use the control user designer to hook up the SampleUserControl_TextChanged.

2. The event handling method that consume the event must be.

private void sampleUserControl1_ValueChanged(object sender,  NamespaceName.ValueChangedEventArgs e)

Cheers from Bolivia.

# re: Finding Controls on Forms

Tuesday, July 28, 2009 10:05 AM by Deborah Kurata

Hi James -

Thank you for your kind comments about the blog and for your tips. I will remove the .Name property as per your suggestion. Thanks again!

# re: Coalesce and Ternary Operators

Tuesday, July 28, 2009 5:25 PM by Chuck Berg

And the coalesce operator can be concatenated, as follows:

currentUser = _currentUser ??

   GetWebUserFromSession() ??

   GetWebUserFromTrackingCookie() ??

   CreateNewWebUser();

Some developers consider this to confusing and difficult to maintain, but I think that over time, people will get used to it and it will become common.

# re: Coalesce and Ternary Operators

Wednesday, July 29, 2009 10:58 AM by Ruddy

As always, very simple and helpful examples that remind us that there is a better way to do things.

Keep it up.

# re: Finding Controls on Forms

Wednesday, July 29, 2009 11:01 AM by Ruddy

This was a great tip. I tried to do this in a web form and it was a really ugly solution with tons of if statements (Controls were in a master page) This is much cleaner and nicer

I love your blog!!

# re: Enum: Binding to the Description Attribute

Thursday, July 30, 2009 1:21 PM by Rob

Deborah,

your solution is lacking of a sort (orderby) metod. Check my ListKeyValuePairEx which you can change for Dictionaries as well:

To use:

<combobox>.BindEnumKeyValue(typeof(<enum>));

or

<combobox>.BindEnumDescriptionValue(typeof(<enum>));

public static class ComboBoxEx

   {

       public static void BindEnumKeyValue(this ComboBox obj, Type enumType)

       {

           obj.DataSource = enumType.EnumToList();

           obj.DisplayMember = "Key";

           obj.ValueMember = "Value";

       }

       public static void BindEnumDescriptionValue(this ComboBox obj, Type enumType)

       {

           obj.DataSource = enumType.EnumDescriptionToList();

           obj.DisplayMember = "Key";

           obj.ValueMember = "Value";

       }

}

public static class EnumEx

   {

       public static IList EnumToList(this Type enumType)

       {

           List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();

           foreach (Enum key in Enum.GetValues(enumType))

           {

               int value = (int)Enum.Parse(enumType, key.ToString());

               list.AddUnique(new KeyValuePair<string, int>(key.ToString(), value));

           }

           return list.SortByKey();

       }

       public static IList EnumDescriptionToList(this Type enumType)

       {

           List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();

           foreach (Enum key in Enum.GetValues(enumType))

           {

               int value = (int)Enum.Parse(enumType, key.ToString());

               list.AddUnique(new KeyValuePair<string, int>(key.GetEnumDescription(), value));

           }

           return list.SortByKey();

       }

       public static string GetEnumDescription(this Enum value)

       {

           return GetEnumAttribute(value, typeof(DescriptionAttribute));

       }

       public static string GetEnumCategory(this Enum value)

       {

           return GetEnumAttribute(value, typeof(CategoryAttribute));

       }

       public static string GetEnumAttribute(this Enum value, Type attribute)

       {

           Type type = value.GetType();

           if (value == null)

           {

               throw new ArgumentException("Value must be of type Enum", "Value");

           }

           System.Reflection.MemberInfo[] memberInfo = type.GetMember(value.ToString());

           if (memberInfo != null && memberInfo.Length > 0)

           {

               object[] attrs = memberInfo[0].GetCustomAttributes(attribute, false);

               if (attrs != null && attrs.Length > 0)

               {

                   return ((DescriptionAttribute)attrs[0]).Description;

               }

           }

           return value.ToString();

       }

   }

public static class ListKeyValuePairEx

   {

       public static List<KeyValuePair<K, V>> AddUnique<K, V>(this List<KeyValuePair<K, V>> list, KeyValuePair<K, V> kv)

       {

           if (!list.Contains(kv))

               list.Add(kv);

           return list;

       }

       public static List<KeyValuePair<K, V>> SortByKey<K, V>(this List<KeyValuePair<K, V>> list)

       {

           List<KeyValuePair<K, V>> sorted = new List<KeyValuePair<K, V>>();

           foreach (KeyValuePair<K, V> item in list.OrderBy(key => key.Key))

           {

               sorted.Add(new KeyValuePair<K, V>(item.Key, item.Value));

           }

           return sorted;

       }

       public static List<KeyValuePair<K, V>> SortByValue<K, V>(this List<KeyValuePair<K, V>> list)

       {

           List<KeyValuePair<K, V>> sorted = new List<KeyValuePair<K, V>>();

           foreach (KeyValuePair<K, V> item in list.OrderBy(key => key.Value))

           {

               sorted.Add(new KeyValuePair<K, V>(item.Key, item.Value));

           }

           return sorted;

       }

   }

# re: Linq: Sorting a DataTable

Wednesday, August 05, 2009 1:07 PM by Rune Brattas

Hi,

Thank you very much for your nice code samples. And a Thank You to you husband who ask about LINQ and DataTable.

I am trying to LINQ my DataTable and return it to my DataGridView. The problem with DataView is that I cannot use distinct and select my fields.

I like to LINQ my DataTable with distinct and select only one (1) field from my DataTable and return it to my DataGridview...any suggestion?

Thank you,

Rune

Rune Brattas @ videotron dot ca

# re: Writing Data from a DataTable to Excel

Friday, August 07, 2009 4:10 PM by Paul Caesar

Deborah,

I've been looking for this code for days. You are my new hero! You saved me hours of effort in making this work.

# re: Validation Class

Saturday, August 08, 2009 3:45 AM by Orson

I love it. I one great post.

Thanks

# re: Building a Business Object Base Class

Saturday, August 08, 2009 8:03 AM by Eric Smith

This all sounds pretty close to an old incarnation of CSLA.NET (We're talking .NET 1.1 days)---I'm wondering if Rocky has moved beyond defining a base class, and then having to hand-code state management into property setters of derived classes?

We considered this approach in the project that we are working on but have moved onto a more flexible (but considerably more advanced) means of managing all that plumbing code that you've baked into your base class, viz., using AOP.

At the end of the day, developers should be concentrating on solving business problems, not writing plumbing and although your base class does take alot of that away, it does mean that you're not stuck deriving from it.  Also, you still need to hand-code that state management and notification stuff into your derived classes---why not just use an AOP framework to bolt that on at runtime?

It does amaze me that after so many years of object orientation and applying MVC goodness, we still haven't got to a place where this is all automagically dealt with by the underlying framework.

# re: Building a Business Object Base Class

Saturday, August 08, 2009 2:55 PM by Yuri

I guess POCO based approach using NHIbernate is way better than implementing  any business logic in your BO's even if it is only SaveItem...

If you have a big project with hundreds of entities you will quickly noticed how unmaintainable it gets

# re: VB or C#?

Saturday, August 08, 2009 4:18 PM by Irfan

It's a great post!! However, I just don't understand the reason of having 2 different languages where the underlying technology (IL) of both is not VERY different. I would agree if it was pre-.NET era where Object-Oriented C++ was more powerful than Object-Based VB. The expectations from both of those languages were quite different. C++ was used for more complex tasks using powerful data structures (linklists, trees, graphs etc.) and on the other hand VB was opted for rapid application development. But, where are we now where almost all of the features are available in both C# and VB.NET with some exceptions. Is it very difficult to implement those exceptions where they are absent?? Is it really impossible to implement XML Literals in C# and Statement Lambda in VB.NET?? if not then I honestly see only one language in future (C# very likely :))

# re: VB or C#?

Saturday, August 08, 2009 8:04 PM by Deborah Kurata

Hi Irfan -

Thank you for visiting my blog.

To reply to your question, VB10 (VS 2010) will have statement lambdas.

# re: TryParse

Tuesday, August 11, 2009 9:48 PM by CB

So there is no distinguishing between the user entering '0' and the user entering 'A'??

# re: Generating Random Numbers

Wednesday, August 12, 2009 9:31 AM by Jack Dolby

Ken Getz also has a nice article that includes generating a collection of random numbers using LINQ:

<msdn.microsoft.com/.../cc700332.aspx>

# re: Generating Random Numbers

Wednesday, August 12, 2009 10:29 AM by Jack Dolby

sorry... the trailing ">" on the url breaks it... I thought <> would prevent url wrapping.

msdn.microsoft.com/.../cc700332.aspx

# re: Generating Random Numbers

Wednesday, August 12, 2009 10:36 AM by Deborah Kurata

Hi Jack -

Thank you for visiting my blog!

Ken's code randomly orders a set of numbers, where my code randomly selects a subset of numbers. Both techniques are useful, depending on your requirements.

NOTE: If you have difficulty using the link in Jack's post, try this: msdn.microsoft.com/.../cc700332.aspx

# re: TryParse

Wednesday, August 12, 2009 10:47 AM by Deborah Kurata

Hi CB -

Thank you for visiting my blog!

You are right in the num will be 0 in both cases. However, if the user enters '0' the If statement will be true. If the user enters 'A', the If statement will be false.

Hope this helps.

# re: Finding Controls on Forms

Wednesday, August 12, 2009 11:00 AM by LotusShiv

Debora,

 Only thing is for ASP.Net replace the HasChildren with HasControls(), in the above Process.... function, there you have it for ASP.Net application environment as well.

I have one such recursive function where in I had to set the checkboxes within a HtmlTable control on a aspx page. So to this function I pass the list of checkbox values and the HtmlTable control. I then check if the current control is a HtmlInputCheckbox and if so, set the checkbox state (checked) if the value of it is one among the list that I have passed as input. Here is the code

       /// <summary>
       ///   Recursive function to set the Checkbox controls within the container control.
       /// </summary>
       /// <param name="listArray"></param>
       /// <param name="ctrlContainer"></param>
       /// <param name="listIndex"></param>
       public static void ProcessCheckboxControls(string[] listArray, Control ctrlContainer, int listIndex)
       {
           HtmlInputCheckBox checkBox = null;
           foreach (Control ctrl in ctrlContainer.Controls)
           {
               if (ctrl.GetType() == typeof(HtmlInputCheckBox))
               {
                   //First initialize the checkbox
                   ((HtmlInputCheckBox)ctrl).Checked = false;

                   //Now set the checked status from the list (if applicable)
                   SetCheckboxFromList(listArray, (HtmlInputCheckBox)ctrl);
                   listIndex++;
                   return;
               }

               if (ctrl.HasControls())
                   ProcessCheckboxControls(listArray, ctrl, listIndex);
           }

       }

       /// <summary>
       ///   Set checkbox from List.
       /// </summary>
       /// <param name="listArray"></param>
       /// <param name="checkBox"></param>
       public static void SetCheckboxFromList(string[] listArray, HtmlInputCheckBox checkBox)
       {
           int i = 0;
           for (i = 0; i < listArray.Length; i++)
           {
               //Check to see if the checkbox value matches with any of the listArray items
               if (checkBox.Value == listArray)
               {
                   checkBox.Checked = true;
                   break;
               }
           }
       }

Thanks

# re: Finding Controls on Forms

Wednesday, August 12, 2009 12:36 PM by Deborah Kurata

Hi LotusShiv -

Thank you for your comment and associated code for use with ASP.NET. Great example!

NOTE: I removed some of the excess blank space between the lines for space reasons. I did not reformat any wrapped lines, however.

Thanks again!

# re: Inferred Typing

Thursday, August 13, 2009 1:42 AM by Yann

Hi Deborah,

I actually don't agree with "Do NOT use inferred typing for variables of intrinsic types (like in the above integer and string examples)".

I use this a lot:

dim title = "This is my title"

I see no point in having to use:

dim title as string = "This is my title"

Am I missing some obscure reasoning here?

Thanks,

Yann

PS - I think you need to change "Questions? Contact Susan at Susan-at-msmvps.com" that's at the bottom of the page, lol.

# re: Generating Random Numbers

Thursday, August 13, 2009 7:57 AM by yemek tarifleri

Good for beginners, Thanks

# re: Generating Random Numbers

Thursday, August 13, 2009 9:08 AM by Chris

You should seed you random numbers; otherwise you'll end up with the same random numbers for every execution of the code.  The common used technique is to seed it with the number of milliseconds from the epoch:

Random rand = new Random(DateTime.Now.Ticks);

# re: DAL: Retrieve a DataTable using a Stored Procedure

Thursday, August 13, 2009 11:49 AM by JP

How are parameters passed in? Can you give me an example?

# re: TryParse

Thursday, August 13, 2009 1:37 PM by Jon Arild Tørresdal

I prefer implementing TryParse using what in DDD is called a Value Object. I have an example here: blog.torresdal.net/.../RefactoringTryParseIntoAValueObject.aspx

# re: Inferred Typing

Thursday, August 13, 2009 4:42 PM by Deborah Kurata

Hi Yann,

Thank you for visiting my blog and for bringing up this topic.

The main reason not to use inferred typing in this case is readability. Read more about this here:

srtsolutions.com/.../on-var-and-c.aspx

And regarding your PS, Susan's name at the bottom is correct. She is the one that manages this blogging site for all of the mvps.

Thanks again!

# re: Generating Random Numbers

Thursday, August 13, 2009 4:51 PM by Deborah Kurata

Hi Chris -

Thank you for visiting my blog and for your suggestion.

However, if you don't specify a seed, the Random method will define one for you so that you don't have the problem you defined. This is a quote from the documentation:

"Initializes a new instance of the Random class, using a time-dependent default seed value."

Here is the link:

msdn.microsoft.com/.../h343ddh9.aspx

Thank you for bringing up this topic!

# re: DAL: Retrieve a DataTable using a Stored Procedure

Thursday, August 13, 2009 5:15 PM by Deborah Kurata

Hi JP -

Thank you for visiting my blog!

I added an example demonstrating how to pass parameters to the ExecuteDataTable method.

Thanks for your suggestion!

# re: TryParse

Thursday, August 13, 2009 5:17 PM by Deborah Kurata

Hi Jon -

Thanks for the link!

# re: DAL: Retrieve a DataTable using a Stored Procedure

Thursday, August 13, 2009 5:53 PM by JP

Very cool.  Multiple params go in as a comma separated list:

Dim dt As DataTable = Dac.ExecuteDataTable("CustomerRetrieveById", _

                        new SqlParameter("@CustomerID", custId), new SqlParameter("@UserID", userId), )

Thanks :)

# re: DAL: Retrieve a DataTable using a Stored Procedure

Thursday, August 13, 2009 5:56 PM by JP

On a side note, how are multiple connections handled?  Lets say a build a data grid, and on item databound I make another database call.

# re: DAL: Retrieve a DataTable using a Stored Procedure

Thursday, August 13, 2009 6:54 PM by Deborah Kurata

Hi JP -

The Using statement ensures that the connection is closed after every call to this function. SQL Server's connection pooling prevents performance issues.

Hope this helps.

# re: TryParse

Friday, August 14, 2009 4:31 AM by notken

I've written an extension method with the help of the generic code here: theengineroom.provoke.co.nz/.../generic-tryparse-type-conversion.aspx

The idea is that you can implement TryParse on any value type by extending the string type, returning a nullable value type, so you can test if the parse was successful. I hope this code shows up in the comments!

public static class Parsing
{
    public static Nullable<T> Parse<T>(this string tryVal) where T : struct
    {
        Nullable<T> result = null;
        try
        {
            int iNumberOfMethods = typeof(T).GetMethods().Length;
            MethodInfo mTryParse = null;
            for (int iCounter = 0; iCounter <= iNumberOfMethods; iCounter++)
            {
                MethodInfo mCurrent = (MethodInfo)typeof(T).GetMethods().GetValue(iCounter);
                if (mCurrent.Name.Equals("TryParse"))
                    {
                    mTryParse = mCurrent;
                    break;
                    }
            }
            if (mTryParse != null)
            {
                T passIn = default(T);
                object[] args = { tryVal, passIn };
                bool success = (bool)mTryParse.Invoke(null, args);
                if (success)
                    result = new Nullable<T>((T)args[1]);
                else
                    result = new Nullable<T>();
            }
        }
        catch { }

        return result;
    }
}

And this is how you would use it:

[Test]
public void Testing_Parse_Helper()
{
    string ok = "123";
    string notOk = "hello";
    int? try1 = ok.Parse<int>();
    double? try2 = notOk.Parse<double>();
    Assert.IsNotNull(try1);
    Assert.AreEqual(try1, 123);
    Assert.IsNull(try2);
}

# re: Generating Random Numbers

Friday, August 14, 2009 8:57 AM by moses

please ,how can you give a customer a unique number which consist at least 10 chars?

# re: TryParse

Friday, August 14, 2009 10:15 AM by Deborah Kurata

Hi Notken -

Thank you for visiting my blog and for your post. The code originally lost all of the formatting, so I had to reformat it. Let me know if I introduced any errors.

Thanks again!

# re: Converting Month Abbreviations to Month Numbers

Friday, August 14, 2009 11:39 AM by Mark Wisecarver

Awesome. You are soooo very much appreciated. Thanks again.

# DAL: Save Data Using a Stored Procedure

Friday, August 14, 2009 12:20 PM by Deborah's Developer MindScape

This post provides an implementation of a method that saves data to a SQL Server database using a stored

# re: Generating Random Numbers

Friday, August 14, 2009 12:23 PM by Deborah Kurata

Hi Moses -

I would not recommend using this random number technique to define unique keys for your customers.

Rather, you should consider either using an autonumber column on your database table or use GUIDS to produce unique Ids.

Here is a link:

msdn.microsoft.com/.../system.guid.aspx

# Painting on the DataGridView - Deborah Kurata

Friday, August 14, 2009 2:01 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Converting Month Abbreviations to Month Numbers - Deborah Kurata

Friday, August 14, 2009 2:04 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: Converting Text to Proper Case

Saturday, August 15, 2009 10:18 AM by John Burns

I'm working with data collected over eons (e.g. 20-30 yrs... mainframe, to DOS DB, to Win DB...). Names have been converted to UpperCase and I would like to make them "normal" - however, I don't want to end up like many bulk mailing printouts - which fail to put proper casing to names like O' Neil, or Mc Murrey, or de la Roma --- and the end up looking like: O'neil, or Mcmurrey, or De la roma

I suspect this would take a huge name database to match against or to just have a huge typefest where names are corrected via "data entry".

Know any automated way?

# re: TryParse

Saturday, August 15, 2009 10:37 AM by vamsi

TryParse in java?

# re: Using Linq with Microsoft Word and Excel

Saturday, August 15, 2009 10:38 AM by Greg Duncan

Nice! Thanks for posting this.

I think you've just saved me hours of future hair-pulling-out... :)

# re: Using Linq with Microsoft Word and Excel

Monday, August 17, 2009 5:45 AM by Daniel Earwicker

Don't overlook the OfType method as an alternative to Cast. The Cast method will throw if the conversion is not allowed, whereas OfType will simply filter non-matching objects out of the sequence. So the OfType method is a bit like the 'as' keyword.

# re: Converting Text to Proper Case

Monday, August 17, 2009 10:10 AM by Deborah Kurata

Hi John -

Thank you for visiting my blog.

One option for handling more complex names is to use the techniques described in this post and build in a set of rules to correct the most common occurrences, such as O'Neil and McMurrey. You could then have the code print to a log for any cases it questioned (like having multiple words in the last name). Then people would only need to look at these exceptions and not every single last name in the database.

Hope this helps.

# re: Using Linq with Microsoft Word and Excel

Monday, August 17, 2009 10:17 AM by Deborah Kurata

Thanks for your suggestion, Daniel.

# DAL: Save Data Using a Stored Procedure - Deborah Kurata

Monday, August 17, 2009 2:30 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Using Linq with Microsoft Word and Excel - Deborah Kurata

Monday, August 17, 2009 2:33 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: DAL: Save Data Using a Stored Procedure

Monday, August 17, 2009 3:56 PM by Neil

Is My.Settings a WinForms thing?  Im assuming its the same as <add key="key" value="value"/> in the web.config?

# Defining Lists of Anonymous Types

Monday, August 17, 2009 5:44 PM by Deborah's Developer MindScape

Similar to my prior post here that details how to use anonymous types to display word counts, this post

# re: Using Linq with Microsoft Word and Excel

Tuesday, August 18, 2009 4:05 AM by Robert Bravery

Fantastic Post. I'm assuming you've tested with office 2007.

# re: DAL: Save Data Using a Stored Procedure

Tuesday, August 18, 2009 11:01 AM by Chester

In the Microsoft Data Access Block, there is a parameter cache. It can automatically fill parameter values for you. So your method can be

public static int ExecuteNonQuery(string storedProcedureName,

                             params object[] arrParam)

It hides the access details behind your method. Users only need to feed values in correct order.

# re: Counting Words in a String Using Anonymous Types

Tuesday, August 18, 2009 1:30 PM by Eric Smith

Or simply:

foreach (var g in Regex.Matches(sampleText.ToLower(),@"\w+")

.Cast<Match>()

.GroupBy(m => m.Value))

Debug.WriteLine(g.Key + ": " + g.Count());

Sorry, no VB.NET.

# re: Using Linq with Microsoft Word and Excel

Tuesday, August 18, 2009 10:07 PM by Deborah Kurata

Hi Robert -

Yes, I tested with Office 2007.

Thanks for visiting my blog!

# Links 2009-08-19

Wednesday, August 19, 2009 7:34 AM by Gunnar Peipman's ASP.NET blog

JQuery and web development Limit Number of Characters in a TextArea using jQuery Find out which Key was

# re: Converting Text to Proper Case

Wednesday, August 19, 2009 4:09 PM by Omar

thanks for your efforts

Public Class DotNetUtility
   Public Shared Function ConvertingTextCase(ByVal str As String, ByVal stringcase As TextCase) As String
       If str Is Nothing Then
           Return String.Empty
       End If

       Dim ci As System.Globalization.TextInfo = Application.CurrentCulture.TextInfo

       Select Case stringcase

           Case TextCase.LowerCase
               str = ci.ToLower(str)
               Exit Select

           Case TextCase.None
               str = str
               Exit Select

           Case TextCase.TitleCase
               str = ci.ToTitleCase(str)
               Exit Select

           Case TextCase.UpperCase
               str = ci.ToUpper(str)
               Exit Select

       End Select
       Return str
   End Function

   Public Shared Function IsRightToLeft(ByVal str As String) As Boolean
       If str Is Nothing Then
           Exit Function
       End If

       Dim ci As System.Globalization.TextInfo = Application.CurrentCulture.TextInfo
       Dim rtl As Boolean

       If ci.IsRightToLeft = True Then
           rtl = True
       Else
           rtl = False
       End If

       Return rtl
   End Function

   Public Enum TextCase
       None = 0
       LowerCase = 1
       TitleCase = 2
       UpperCase = 3

   End Enum

End Class

 

# re: Converting Text to Proper Case

Wednesday, August 19, 2009 4:30 PM by Deborah Kurata

Hi Omar -

Thank you for sharing your code.

NOTE: I removed some of the excess line spacing that was inserted by the editor here.

Thanks again!

# re: Processing Files Using Anonymous Types

Wednesday, August 19, 2009 6:45 PM by CB

The "useful scope" of the anonymous type is pretty much what you can see on screen, right?  It seems that there is little you can do with the query result unless you know exactly what the

'select new {...}' statement looked like.

Or is that somehow discoverable?

These are very useful posts, thanks for putting them uip.

# Microsoft spotlight: MVP Deborah Kurata

Wednesday, August 19, 2009 6:55 PM by No1 Microsoft Fan

I’ve been keeping an eye on Deborah’s MSMVPS blog and am amazed. Deborah is posting some awesome code

# Microsoft spotlight: MVP Deborah Kurata

Wednesday, August 19, 2009 6:55 PM by No1 Microsoft Fan

I’ve been keeping an eye on Deborah’s MSMVPS blog and am amazed. Deborah is posting some awesome code

# Microsoft spotlight: MVP Deborah Kurata

Wednesday, August 19, 2009 6:55 PM by No1 Microsoft Fan

I’ve been keeping an eye on Deborah’s MSMVPS blog and am amazed. Deborah is posting some awesome code

# Interesting Finds: August 20, 2009

Thursday, August 20, 2009 6:41 AM by Jason Haley

Interesting Finds: August 20, 2009

# Interesting Finds: August 20, 2009

Thursday, August 20, 2009 6:41 AM by Jason Haley

Interesting Finds: August 20, 2009

# Anonymous Types: An Introduction - Deborah Kurata

Thursday, August 20, 2009 9:47 AM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Processing Files Using Anonymous Types - Deborah Kurata

Thursday, August 20, 2009 9:48 AM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: Processing Files Using Anonymous Types

Thursday, August 20, 2009 11:49 AM by Bob Bingham

I don't get it.  Why strip the file objects down to just the four properties?  If you were going to pass the anonymous type out to other routines then I could see having security reasons to do something like that but anonymous types need to stay within the routine.  Wouldn't you rather just use the file types you already pulled with .GetFiles?

# re: Processing Files Using Anonymous Types

Thursday, August 20, 2009 11:54 AM by Deborah Kurata

Hi CB -

Yes, the useful scope of an anonymous type is primarily restricted to the routine in which it was defined.

If it had a more significant scope, a named type (basically a class) should be used instead.

Thanks for visiting my blog!

# re: Processing Files Using Anonymous Types

Thursday, August 20, 2009 12:05 PM by Deborah Kurata

Hi Bob -

Thanks for visiting my blog.

There are lots of properties on the file objects. If you had lots of code where I have "Do whatever ..." and that code only used the four properties, it might be helpful to only have the four properties showing up in Intellisense.

In *real* projects where I have used this, we have also defined properties that modified the built-in properties such as defining the .FileName property without an extension or removing the "." from the extension.

Hope this helps.

# re: Coalesce and Ternary Operators

Friday, August 21, 2009 3:46 AM by Andy Rose

Completely forgotten about the coalesce operator. Thanks for the reminder. Great blog by the way.

# Interesting Finds: August 21, 2009

Friday, August 21, 2009 6:57 AM by Jason Haley

Interesting Finds: August 21, 2009

# re: Anonymous Types: An Introduction

Friday, August 21, 2009 9:28 AM by Waleed El-Badry

Thanks Deborah for your recurring contribution. You are priceless to Visual Basic community.

# re: Adding Nodes to an XML String

Friday, August 21, 2009 9:44 AM by Waleed El-Badry

Hello Deobrah,

Don't you agree that importing Schema would simplify the LINQ query to avoid mistyping errors?

Thanks again for your lovely post

# re: Anonymous Types: An Introduction

Friday, August 21, 2009 2:47 PM by Cliff Jacobson

One small typo, this feature was available with Visual Studio 2008 which shipped with .NET 3.5 which includes C# 3.0 and VB 9.0.

For Visual Studio 2010 and .NET 4.0 there is going to be C# 4.0 and VB 10.0.

# re: Anonymous Types: An Introduction

Friday, August 21, 2009 3:45 PM by Deborah Kurata

Hi Cliff -

You are correct.

I have been working on VS 2010 articles and typed "2010" here when it is "2008". I correct the text.

Thanks!

# DAL: Save Data Using a SQL Statement

Friday, August 21, 2009 4:13 PM by Deborah's Developer MindScape

This post provides an implementation of a method that saves data to a SQL Server database using a SQL

# DAL: Save Data Using a SQL Statement

Friday, August 21, 2009 4:13 PM by Deborah's Developer MindScape

This post provides an implementation of a method that saves data to a SQL Server database using a SQL

# Adding Nodes to an XML String - Deborah Kurata

Sunday, August 23, 2009 2:56 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: Counting Words in a String Using Anonymous Types

Sunday, August 23, 2009 7:07 PM by Joacim Andersson

The phrase in the sample string comes from the movie "Flowers for Algernon".

# DAL: Save Data Using a SQL Statement - Deborah Kurata

Sunday, August 23, 2009 8:00 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Nifty extension methods

Monday, August 24, 2009 8:56 AM by Joacim's view on stuff

One of my favorite features in .Net 3.5 is the ability to extend a class using extension methods. Earlier

# Text Files

Tuesday, August 25, 2009 1:09 PM by Deborah's Developer MindScape

There are many different types of text files that you may need to process in your applications. Some

# re: Text Files

Tuesday, August 25, 2009 2:04 PM by Neil

No mention of JSON?

# Reading Comma Delimited Files

Tuesday, August 25, 2009 2:14 PM by Deborah's Developer MindScape

There may be times that you need to read delimited comma files into your application. For example, you

# Reading Comma Delimited Files

Tuesday, August 25, 2009 2:14 PM by Deborah's Developer MindScape

There may be times that you need to read delimited comma files into your application. For example, you

# re: Counting Words in a String Using Anonymous Types

Tuesday, August 25, 2009 2:19 PM by Deborah Kurata

Hi Eric -

Thanks for the suggestion. See the update at the end of my blog. I added the OrderBy and the associated VB code.

Thanks again!

# re: Counting Words in a String Using Anonymous Types

Tuesday, August 25, 2009 2:20 PM by Deborah Kurata

Hi Joacim -

You are correct!

Thanks for visiting my blog!

# re: Reading Comma Delimited Files

Tuesday, August 25, 2009 2:58 PM by Reed Copsey

This seems like more work than using TextFieldParser directly.  You're giving up a lot of error checking, and adding extra overhead loading the odbc + ado.net drivers.  Why not just use msdn.microsoft.com/.../microsoft.visualbasic.fileio.textfieldparser.aspx ?

# Reading Fixed Length Files

Tuesday, August 25, 2009 3:34 PM by Deborah's Developer MindScape

There may be times that you need to read fixed length files into your application. For example, you obtain

# Reading Fixed Length Files

Tuesday, August 25, 2009 3:34 PM by Deborah's Developer MindScape

There may be times that you need to read fixed length files into your application. For example, you obtain

# Reading Fixed Length Files

Tuesday, August 25, 2009 3:43 PM by Deborah's Developer MindScape

There may be times that you need to read fixed length files into your application. For example, you obtain

# re: Text Files

Tuesday, August 25, 2009 3:45 PM by Deborah Kurata

Hi Neil -

Thank you for stopping by my blog.

I was focused on describing enough about text files to then write the next two posts, which involve reading text files using OleDb.

You would not use OleDb to read in JSON files. But for completeness, I'm glad you mentioned it here.

Thanks again!

# re: Reading Comma Delimited Files

Tuesday, August 25, 2009 4:07 PM by Deborah Kurata

Hi Reed -

Thank you for visiting my blog and thanks for the link!

There are benefits of reading the data into a DataTable, such as the ability to then bind to controls such as a DataGridView.

Using the technique you suggested is another choice if the application just needs to process the file line by line.

Thanks again!

# Reading Comma Delimited Files

Tuesday, August 25, 2009 4:37 PM by Deborah's Developer MindScape

There may be times that you need to read comma separated value (CSV) files into your application. For

# Reading Comma Delimited Files: TextFieldParser

Tuesday, August 25, 2009 4:59 PM by Deborah's Developer MindScape

In my prior post, I covered how to read a comma delimited file into an in-memory DataTable. You could

# Reading Fixed Length Files: TextFieldParser

Tuesday, August 25, 2009 5:05 PM by Deborah's Developer MindScape

In my prior post, I covered how to read a fixed length file into an in-memory DataTable. You could then

# Formatting Text Files

Tuesday, August 25, 2009 5:08 PM by Deborah's Developer MindScape

There are often times that you need to write out text files containing data managed by your application

# Formatting Text Files

Tuesday, August 25, 2009 5:08 PM by Deborah's Developer MindScape

There are often times that you need to write out text files containing data managed by your application

# Text Files

Tuesday, August 25, 2009 5:10 PM by Deborah's Developer MindScape

There are many different types of text files that you may need to process in your applications. Some

# Text Files

Tuesday, August 25, 2009 5:10 PM by Deborah's Developer MindScape

There are many different types of text files that you may need to process in your applications. Some

# re: Reading Comma Delimited Files

Tuesday, August 25, 2009 5:13 PM by Deborah Kurata

Hi Reed -

I just added posts for using TextFieldParser to access a comma delimited value (CSV) file and a fixed length file. Thanks for the suggestion!

# re: Text Files

Tuesday, August 25, 2009 7:16 PM by Waleed El-Badry

Thanks Deborah for this post.

Is there a chance to see a post related to interacting with Excel from VB? I'm not talking about VSTO but using automation.

Regards

# Retrieve a DataTable using Microsoft Access

Tuesday, August 25, 2009 7:20 PM by Deborah's Developer MindScape

Despite the fact that there is a free version of SQL Server called SQL Server Express , there are still

# Update a Microsoft Access Database

Tuesday, August 25, 2009 7:29 PM by Deborah's Developer MindScape

Despite the fact that there is a free version of SQL Server called SQL Server Express , there are still

# re: Text Files

Tuesday, August 25, 2009 7:34 PM by Deborah Kurata

Hi Walleed -

I have done several Excel examples:

msmvps.com/.../default.aspx

Hope this helps.

# Interesting Finds: August 28, 2009

Friday, August 28, 2009 6:16 AM by Jason Haley

Interesting Finds: August 28, 2009

# Wonderful blog

Friday, August 28, 2009 4:51 PM by Gizi Ben-Tovim

Thanks Deborah for these very helpful tips and code  sections.

Also, this is one of the few expert blogs where VB programmers are not ignored!

# Code Reviews - Deborah Kurata

Sunday, August 30, 2009 1:35 AM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: Converting Text to Proper Case

Monday, August 31, 2009 9:02 AM by Kevin S Gallagher

Focusing on making text proper case, if the incoming text is all uppercase then .ToLower method is needed.

using the following

 <Runtime.CompilerServices.Extension()> _
   Public Function ProperCase(ByVal value As String) As String
       Dim TI As System.Globalization.TextInfo = New System.Globalization.CultureInfo("en-US", False).TextInfo
       Return TI.ToTitleCase(value.ToLower)
   End Function

with this data

       Dim Mary = (From name In New String() _
                   {"MARY JONE'S", "mary jone's", "Mary jone'S"} _
                   Select name.ProperCase).ToList
       Mary.ForEach(AddressOf Console.WriteLine)

Outputs

MARY JONE's
Mary Jone's
Mary Jone's
MARY JONE's
Mary Jone's
Mary Jone's

Now add .ToLower

   <Runtime.CompilerServices.Extension()> _
   Public Function ProperCase(ByVal value As String) As String
       Dim TI As System.Globalization.TextInfo = New System.Globalization.CultureInfo("en-US", False).TextInfo
       Return TI.ToTitleCase(value.ToLower)
   End Function

We get proper casing correct

Mary Jone's
Mary Jone's
Mary Jone's
Mary Jone's
Mary Jone's
Mary Jone's

 

# re: Populating a TreeView Control from XML

Monday, August 31, 2009 9:33 AM by Prince.C

Thanks a lot..you saved me..:)

# re: Reading Comma Delimited Files

Monday, August 31, 2009 10:25 AM by Steve

I'm trying the C# solution and I keep getting an error that the Microsoft Jet Engine cannot open the file ''.  That only thing different that I'm doing is instead of a OleDbConnection, I have a string in it's place.  Does the directory name for the data source need to have a \ at the end?

# re: Reading Comma Delimited Files

Monday, August 31, 2009 1:50 PM by Deborah Kurata

Can you post this question along with a code snippet here:

social.msdn.microsoft.com/.../threads

I monitor this C# forum and here it will be easier to look at your code and have a "conversation".

Thanks for visiting my blog!

# re: What is OO?

Monday, August 31, 2009 3:58 PM by Waleed El-Badry

Thanks Deborah for this lovely article with simple non-complex overview that we all adore in your distinguishable articles.

Why didn't you add a simple blank methods and properties to demonstrate how real world objects can be casted to VB Code?

Also we hope that the following article would talk a bit about pillars of OOP like encapsulation and inheritance in your way that charms all VB fans -what is your secret? :-)

Have a lovely day

# Compacting code

Monday, August 31, 2009 4:19 PM by Ted

Reducing the number of lines of code and improving code documentation are focused on in our code reviews.

# re: What is OO?

Monday, August 31, 2009 5:51 PM by Deborah Kurata

Hi Waleed -

Thank you for visiting my blog and for the kind words.

These are all upcoming topics. Did not want to make any one topic too long. :-)

# What is OO?

Monday, August 31, 2009 5:55 PM by Deborah's Developer MindScape

Today’s world of software design and development is all about managing complexity. Computer-savvy users

# What is OO?

Monday, August 31, 2009 5:55 PM by Deborah's Developer MindScape

Today’s world of software design and development is all about managing complexity. Computer-savvy users

# What is OO?

Monday, August 31, 2009 5:57 PM by Deborah's Developer MindScape

Today’s world of software design and development is all about managing complexity. Computer-savvy users

# Interesting Finds: September 1, 2009

Tuesday, September 01, 2009 7:08 AM by Jason Haley

Interesting Finds: September 1, 2009

# What is Inheritance?

Tuesday, September 01, 2009 10:58 AM by Deborah's Developer MindScape

In object-oriented (OO) terms, inheritance defines an “is a” relationship between two or more classes

# What is Inheritance?

Tuesday, September 01, 2009 10:58 AM by Deborah's Developer MindScape

In object-oriented (OO) terms, inheritance defines an “is a” relationship between two or more classes

# What is an Interface?

Tuesday, September 01, 2009 11:29 AM by Deborah's Developer MindScape

When talking about OO, the term “interface” has nothing to do with your user interface. An interface

# What is an Interface?

Tuesday, September 01, 2009 11:29 AM by Deborah's Developer MindScape

When talking about OO, the term “interface” has nothing to do with your user interface. An interface

# What is OO?

Tuesday, September 01, 2009 11:31 AM by Deborah's Developer MindScape

Today’s world of software design and development is all about managing complexity. Computer-savvy users

# What is OO?

Tuesday, September 01, 2009 11:39 AM by Deborah's Developer MindScape

Today’s world of software design and development is all about managing complexity. Computer-savvy users

# Basic Pillars of an Object-Oriented System

Tuesday, September 01, 2009 12:16 PM by Deborah's Developer MindScape

The four basic elements of an object-oriented system are abstraction , encapsulation , inheritance ,

# Basic Pillars of an Object-Oriented System

Tuesday, September 01, 2009 12:16 PM by Deborah's Developer MindScape

The four basic elements of an object-oriented system are abstraction , encapsulation , inheritance ,

# Basic Pillars of an Object-Oriented System

Tuesday, September 01, 2009 12:16 PM by Deborah's Developer MindScape

The four basic elements of an object-oriented system are abstraction , encapsulation , inheritance ,

# re: Reading Comma Delimited Files

Wednesday, September 02, 2009 4:37 AM by radarek

Hey, one question regarding this code:

What about UTF-8 text file and the special characters?

I have tested it and this code doesn't read multibyte character - so isteed one 2byte character you will get two 1 byte characters. Oh and Byte Order Mask at the begining is also visible :)

# Interesting Finds: September 2, 2009

Wednesday, September 02, 2009 7:11 AM by Jason Haley

Interesting Finds: September 2, 2009

# Interesting Finds: September 2, 2009

Wednesday, September 02, 2009 7:11 AM by Jason Haley

Interesting Finds: September 2, 2009

# Interesting Finds: September 2, 2009

Wednesday, September 02, 2009 7:11 AM by Jason Haley

Interesting Finds: September 2, 2009

# re: Reading Comma Delimited Files

Wednesday, September 02, 2009 10:02 AM by Deborah Kurata

Hi Radarek -

Thanks for stopping by the blog. Yes, this technology is a little limited. There is an OEM mode (instead of the ANSI mode), but I did not try it. If you give it a try, report back and let us know if it worked for you.

Hope this helps.

# re: Nullable Data Types

Wednesday, September 02, 2009 5:57 PM by Mark Wisecarver

Awesome! Please don't stop now.  ;-)

 All the best,

   Mark Wisecarver

# re: Global Exception Handler (WinForms)

Thursday, September 03, 2009 12:16 PM by Chris Madsen

Thanks for the interesting article. I had never tried using Application Events because my app doesn't start from a form, which is required. Finally (duh) I realized that a tiny dummy form that hands off to my Sub Main would do the trick. Your article gave me the push.

# re: Building an Alarm Class

Thursday, September 03, 2009 1:28 PM by es

what timers ?? what class ? there are three timers class !!!

# re: Building an Alarm Class

Thursday, September 03, 2009 2:11 PM by Deborah Kurata

Hi es -

Thank you for visiting my blog.

It does not really matter to the code which timer you use. Rather, it will depend on your application.

I used the System.Windows.Forms.Timer because my example was executed from a WinForm. You may want to pick one of the others, depending on how you use this class.

# re: Global Exception Handler (WinForms)

Friday, September 04, 2009 12:36 AM by Amit

              I have tried this thing before. I wanted to catch StackOverflowException.  But this thing is not working for StackOverflowException. For all other exceptions, this mechanism is perfect.    

# re: Painting on the DataGridView

Friday, September 04, 2009 4:53 AM by John Braga

Thank you for the above code.  Works very well, except for one small error in the c# code.  You set an integer rowHeaderWidth which will be 0 if row headers are NOT visible, but then you do not use it when setting the rectangle bounds, so the rectangle is offset.

I think rowHeaderswidth in the VB example should be rowHeaderwidth, but have not tested it.

# re: Painting on the DataGridView

Friday, September 04, 2009 10:36 AM by Deborah Kurata

Hi John -

Thank you for catching that! I corrected the code in the post.

Thanks again -

# re: Enumerable.Range

Friday, September 04, 2009 9:10 PM by Waleed El-Badry

You still impress me with your magical way in your posts. However, I blame using lambda expression since it makes me lose focus on the feature you try to explain. I've noticed that you fell in love with the anonymous function as you used it intensively in your last posts.

Thanks again and stay brilliant as you are :-)  

# re: Enumerable.Repeat

Friday, September 04, 2009 9:24 PM by Waleed El-Badry

This is a very important feature to perform dummy repetition of the same data over and over and a strong replacement of the traditional loop since it is an inline function.

Thanks Deborah. This post is beyond amazing

# re: Nullable Data Types

Friday, September 04, 2009 9:48 PM by Waleed El-Badry

I remember studying the nullable types when I was preparing for the .NET Framework 2.0 exam as it was in the very beginning of the Microsoft self paced kit.

The good thing is you used "ternary operator" which would do the job correctly.Developers may mix it up with "the immediate IF (IIF)" which would sometimes causes a logical bug that is hard to be found since many are not aware that it evaluates both true and false parts if they were functions.

Thanks Deborah. You touched a vivid topic.

# Уважаю статьи написанные с душой и качественно

Saturday, September 05, 2009 5:33 PM by Arsento

Мегареспектос! Прочитал с интересом от начала и до конца.

# Nullable Data Types - Deborah Kurata

Sunday, September 06, 2009 3:27 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Enumerable.Repeat - Deborah Kurata

Sunday, September 06, 2009 3:29 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: Validation Class

Sunday, September 06, 2009 7:40 PM by Joseph Homshaw

What a great class, thank you very much!!

# re: Enumerable.Range

Sunday, September 06, 2009 8:33 PM by Joacim Andersson

If you don't like to use lambda expression you can just as well use a regular LINQ query and let the compiler create the lambda for you.

   ' Initialize an array with letters

   ' This one does A, B, ... J

   Dim letters() As String = (From i In Enumerable.Range(0, 10) _

                              Select (Chr(Asc("A") + i).ToString())).ToArray()

# re: Enumerable.Range

Sunday, September 06, 2009 11:37 PM by Wes McClure

A spin off of the python range method?

# Using Code Snippets

Tuesday, September 08, 2009 1:24 PM by Deborah's Developer MindScape

Are there some pieces of code that you find yourself writing over and over and over again? Do you ever

# Understanding Object Binding

Tuesday, September 08, 2009 2:26 PM by Deborah's Developer MindScape

Before going through the details of how to use object binding, it is important to understand exactly

# DAL: Data Access Layer

Tuesday, September 08, 2009 2:49 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# DAL: Data Access Layer

Tuesday, September 08, 2009 2:49 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# DAL: Data Access Layer

Tuesday, September 08, 2009 2:49 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# Using Object Binding

Tuesday, September 08, 2009 5:23 PM by Deborah's Developer MindScape

As stated here , you use object binding in a WinForms application by following these steps: 1. Build

# Interesting Finds: September 9, 2009

Wednesday, September 09, 2009 7:19 AM by Jason Haley

Interesting Finds: September 9, 2009

# Interesting Finds: September 9, 2009

Wednesday, September 09, 2009 7:19 AM by Jason Haley

Interesting Finds: September 9, 2009

# Interesting Finds: September 9, 2009

Wednesday, September 09, 2009 7:19 AM by Jason Haley

Interesting Finds: September 9, 2009

# re: Writing Data from a DataTable to Excel

Wednesday, September 09, 2009 8:06 AM by Ken

Love the code; it works great with my code to pull XML data from a website into a dataset.  One question though.  If I want to leave the Excel file open so I can do further work on it, how do I do so with out leaving garbage out there?

# re: Using Code Snippets

Thursday, September 10, 2009 2:15 AM by Waleed El-Badry

Thanks Deborah for submitting this article. But what about creating custom code snippets using snippet editor. I usually code the snippet in the XML editor, however, I hope you can highlight the usage of the code snippet editor as I believe it would be much easier to work with.

Have a lovely day

# re: Reading Fixed Length Files

Thursday, September 10, 2009 3:30 PM by Chris

Trying this on a fixed width file, but it doesn't work unless I have an end of line character.  The file I am working with is just one long stream of characters.  Thanks anyway!

# re: Populating a TreeView Control from XML

Friday, September 11, 2009 4:02 PM by Jeff

Very straight forward and it helped a lot.– thanks for posting it!

# Interesting Finds: 2009 09.06 ~ 09.14

Monday, September 14, 2009 12:33 AM by gOODiDEA.NET

.NET Comparing Two Images in C# Application running in localhost and debugging mode - HttpContext.Current

# Interesting Finds: 2009 09.06 ~ 09.14

Monday, September 14, 2009 12:38 AM by gOODiDEA

.NETComparingTwoImagesinC#Applicationrunninginlocalhostanddebuggingmode-HttpCo...

# re: Using Linq with Microsoft Word and Excel

Monday, September 14, 2009 5:26 PM by David Sutherland

I just wanted to thank you for this post too.  I was just starting to do Linq to Word for a project and this posting came riding to the rescue.

Cheers;

Dave

# re: DAL: Retrieve a DataTable using a Stored Procedure

Wednesday, September 16, 2009 5:38 AM by Jim Hardwork

Can you post a soltion file with all code in the related Data Access examples.

# re: DAL: Retrieve a DataTable using a Stored Procedure

Wednesday, September 16, 2009 10:17 AM by Deborah Kurata

Hi Jim -

There are examples here:

www.insteptech.com/.../samplecode.htm

Hope this helps.

# Using the Code Snippet Editor

Wednesday, September 16, 2009 7:34 PM by Deborah's Developer MindScape

After my post on Using Code Snippets , several people have asked about the Code Snippet Editor. As stated

# Binding Control Properties to Business Object Properties - Deborah Kurata

Friday, September 18, 2009 8:54 AM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: DAL: Using Stored Procedures

Sunday, September 20, 2009 7:18 AM by Antonio.B

Very well-written article and very understandable. Also helped me with a problem I've had for some time, thanks!

# re: DAL: Save Data Using a SQL Statement

Monday, September 21, 2009 2:51 AM by seesharpgears

Hello, this is a good approach for wrapping up the database access, but I just wanted to note few things here: this solution is no flexible for usage with different SQL providers and it still returns ADO.NET's standard objects like DataTables etc., meaning the developer who uses this code would still need to map the data fields into her C# objects manually, which is tedious and time-consuming. Just as a suggestion, you could read my post: <b><a href="seesharpgears.blogspot.com/.../csharpgears-framework-database-access.html" title="Database Wrapper Classes" >Database Wrapper Classes</a></b> which utilizes a framework for designing a wrapping the whole access to the database to four operations Select(), Update(), Delete() and Insert() and is capable of directly mapping the SQL columns to C# attributes, meaning that a SQL table Product corresponds to a C# class Product and the Select() query would return List<Product> directly, which makes it easier for OOP manipulation. Please read my approach and tell me what do you think. All comments are appreciated.

# Randomly Pick Items From a List

Monday, September 21, 2009 5:29 PM by Deborah's Developer MindScape

There are often times in most applications where you need to work with lists. You may have lists of customer

# Write a Memorization Helper Application

Monday, September 21, 2009 7:24 PM by Deborah's Developer MindScape

Though this is not necessarily a common requirement, this post demonstrates the following techniques

# Write a Memorization Helper Application

Monday, September 21, 2009 7:24 PM by Deborah's Developer MindScape

Though this is not necessarily a common requirement, this post demonstrates the following techniques

# Write a Memorization Helper Application

Monday, September 21, 2009 7:31 PM by Deborah's Developer MindScape

Though this is not necessarily a common requirement, this post demonstrates the following techniques

# re: Randomly Pick Items From a List

Wednesday, September 23, 2009 4:37 PM by Arielr

yourList.OrderBy(x=>Guid.NewGuid()).Take(numberOfItems);

# re: DAL: Retrieve a DataTable using a Stored Procedure

Wednesday, September 23, 2009 8:51 PM by gamena

hi deborah,

just want to ask if you have a sample n-tier architecture, 5-tiers which includes entities, DAL, proxy, UI and data source-

im trying to make a system using this 5 tiers for the winforms application...

hope you can help me with this. a sample program could help. with add, delete, update and edit using stored procs.

many thanks. God bless.

# re: Reflection: Displaying a Form By Name

Thursday, September 24, 2009 1:35 PM by Jim Kahl

This works great as long as you are calling a form that resides inside the assembly.  I need to be able to display a form that resides in another assembly.  I have tried many samples on the internet and find that they do not work and either give me a null reference exception as soon as I try frm.Show or when I try to invoke the Show method as (obj.GetMethod("Show").Invoke(inst, Nothing)) it gives an ambiguous name exception.  How can I perform this?

# re: Writing Data from a DataTable to Excel

Thursday, September 24, 2009 5:30 PM by Marton Toth

Hi,

I use Excel 2008 on Mac. It does not enable the use of macros. I am not familiar with Applescript or C#.

My question is pretty similar and I wonder if it can be solved without the use of macros. I have several columns of data (heading is constant, length of columns could differ), which has to be transformed to fit to a statistical software so that each cell in the column produces as many cells beneath in the same column as the value of the cell (not negative integer). The value of the newly generated cells are the sequential number of the original cell in the column (except for the heading).

Eg:

XY

0

0

1

3

4

8

This column should produce altogether 16 cells in the same column (or new spreadsheet) 1 with the value "3", 3 with the value "4", 4 with the value "5" and 8 with the value "6" (the sequential number could be read out form an other parallel column as well).

I would very much appreciate if you could help solving ths frustrating problem.

M.

# re: DAL: Retrieve a DataTable using a Stored Procedure

Friday, September 25, 2009 11:57 AM by Deborah Kurata

Hi Gamena -

The sample application I have is here:

www.insteptech.com/.../samplecode.htm

Enjoy!

# re: Writing Data from a DataTable to Excel

Friday, September 25, 2009 12:04 PM by Deborah Kurata

Hi Marton -

My blog primarily focuses on .NET development. You may want to try posting your question to an Excel forum.

Good luck!

# DAL: Using a Data Provider Factory

Friday, September 25, 2009 6:59 PM by Deborah's Developer MindScape

Whether it be SQL Server, Access, Oracle, or mySql, most applications write to one kind of database.

# DAL: Data Access Layer

Friday, September 25, 2009 7:02 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# DAL: Data Access Layer

Friday, September 25, 2009 7:02 PM by Deborah's Developer MindScape

One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter

# re: Count Lines Of Code

Saturday, September 26, 2009 5:05 AM by Bernard Londeix

Hello Deborah,

Welcome to the metrics world. You have just demonstrated that the functionality, what is useful to the user, is not the programming language but what is hiding behind the language (i.e. the IDE and the OS) and how the language is used by the programmer.

I bet that, had you measured the functionality with COSMIC (www.cosmicon.com) you would have found the same number for VB6 as for .NET. This is because COSMIC measures the functionality and not the lines of code.

This being said I like your code, I'll try it.

Best regards,

Bernard Londeix

Telmaco Ltd (www.telmaco.com)

# re: Count Lines Of Code

Saturday, September 26, 2009 9:33 AM by JL

Please explain:

// Process the directory and all subdirectories

in the C# program,

it seems to me that only the subdirectories are processed.

If *.cs programs are in the top directory, they will not be added.

Thanks

# re: DAL: Using a Data Provider Factory

Saturday, September 26, 2009 12:18 PM by Shaw G

I can't believe that MS would have made it so trivial to code for multiple database types.

In Java, we will have to use an elaborate DAO pattern using one of Sun's blueprint, like this one:

java.sun.com/.../DataAccessObject.html

Or use DAO facility by one of the leading frameworks, Spring's DAO comes to mind.

Or use an ORM like Hibernate.

Anyway, is this provider method widely used in MS. I mean is it widely used if you are not using ORM (like nHibernate) or other open source frameworks like Spring.NET?

# re: DAL: Using a Data Provider Factory

Sunday, September 27, 2009 3:48 AM by Masoud

very nice post.

thats my always problem with different dbms

thanks

;)

# re: DAL: Using a Data Provider Factory

Monday, September 28, 2009 10:02 AM by Conrad

What do we do with exceptions?  Are the exceptions raised provider-specific?

# re: DAL: Using a Data Provider Factory

Monday, September 28, 2009 10:05 AM by HoyaBaptiste

Won't the use of SqlParameter... ParamArray arrParam() As SqlParameter... still bind this approach to Sql Server provider?

# re: DAL: Using a Data Provider Factory

Monday, September 28, 2009 11:32 AM by Deborah Kurata

Hi HoyaBaptiste -

Oops! I did not correctly handle the parameters in this code. I will edit the post to correct it.

Thanks!

# re: DAL: Using a Data Provider Factory

Monday, September 28, 2009 11:57 AM by Deborah Kurata

Hi Conrad -

This is from the msdn documentation:

"The DbException class is the base class for all exceptions thrown on behalf of a data source. You can use it in your exception handling code to handle exceptions thrown by different providers without having to reference a specific exception class."

Here is the link:

msdn.microsoft.com/.../9hy8csk1.aspx

Hope this helps.

# re: Global Exception Handler (WinForms)

Tuesday, September 29, 2009 8:33 AM by Kevin S Gallagher

In my agency all .NET WinForm solutions have global unhandled exception handlers using this technique. Besides logging information to an XML log file developers have the option to send exceptions to a specially setup mailbox. The mailbox has rules setup to send known applications exceptions to sub folders which are monitored. The advantage here is that many times a developer will see a message; fix the issue before a user calls in the problem which in turn equates back to the customer as good customer service on our end. All our unhandled exception handling is housed in a separate DLL (includes a custom dialog which morphs between user and technician interface) which makes it easy for a developer to plug in this functionality Susan is talking about. Sometime in the near future I will be releasing the source code including demonstration projects used to test this code which has made several jumps in Frameworks with no changes other than improvements. Location will be under code.msdn.microsoft.com/kevininstructor

# re: Count Lines Of Code

Tuesday, September 29, 2009 10:53 PM by Rich Quackenbush

Also, there are some tools built into Visual Studio 2008 that will give you this (and much more information):

blogs.msdn.com/.../new-for-visual-studio-2008-code-metrics.aspx

Of course, this will only work for .NET projects.

# re: Count Lines Of Code

Tuesday, September 29, 2009 11:56 PM by Deborah Kurata

Hey Rich!

Good to hear from you. Thanks for pointing to this link. There are some really nice tools there.

One note on the tool you mentioned .... I believe that it is only available in Visual Studio Team Editions.

Thanks again!

# re: Using Code Snippets

Friday, October 02, 2009 5:00 PM by Danny

Great way to manage snippets. There are more at www.snippetgood.com

# re: Silicon Valley Code Camp

Friday, October 02, 2009 10:52 PM by shivaji

looking forward

# re: Populating a TreeView Control from XML

Sunday, October 04, 2009 1:58 PM by Joakim Westin

Thanks for a great little post. Well written and very clear :-)

# re: Writing Data from a DataTable to Excel

Monday, October 05, 2009 12:59 AM by Manu

Please tell me what is this "missing" field ??  

# another method to do this

Monday, October 05, 2009 9:02 AM by Greg

Here is a 2 liner for it

  wc.exe *.cs

  wc.exe *.vb

This is on many platforms unix, linux, win32...

WC(1) User Commands WC(1)

NAME

      wc - print the number of newlines, words, and bytes in files

SYNOPSIS

      wc [OPTION]... [FILE]...

DESCRIPTION

      Print newline, word, and byte counts for each FILE, and a total line if

      more than one FILE is specified.  With no FILE, or when FILE is -, read

      standard input.

      -c, --bytes

     print the byte counts

      -m, --chars

     print the character counts

      -l, --lines

     print the newline counts

      -L, --max-line-length

     print the length of the longest line

      -w, --words

     print the word counts

      --help display this help and exit

      --version

     output version information and exit

# re: Writing Data from a DataTable to Excel

Monday, October 05, 2009 10:40 AM by Deborah Kurata

Hi Manu -

Thank you for stopping by the blog. Missing.Value is needed in C# because C# 3.0 does not support optional parameters.

Here is a link to the msdn documentation on Missing.Value:

msdn.microsoft.com/.../system.reflection.missing.value.aspx

# re: DAL: Using a Data Provider Factory

Wednesday, October 07, 2009 2:12 PM by John Wright

I created code similar to this in 2005 when the data factory came out.  I created a class that I can drop into any project and used shared functions that I call.  I account for returned datatables, return an object for ExecuteScalar functions, and I also have an execute nonquerySQL that returns nothing.  The class has a parameter object with typed parameters, and so far has been tested successfully with SQL Server, Oracle, text files, Excel, and ODBC against a mainframe.  It will even account for the oracle refCursor returns as well for returning cursors from oracle.  

In addition, I created a slick little application that goes against any SQL Server database on the network, lists all the stored procedures, and generates the calling code for me, complete with all return types, and typed parameters.  Cut my programming time down by 80% and eliminated quite a bit of debugging since the code has been tested and is quite effective.  I think the best thing .NET 2.0 put in was the data factory.  

John

riley_wright@hotmail.com

# But what about attributes?

Friday, October 09, 2009 8:23 AM by Jerry T.

This looks very simple. Is this an aspect of LINQ or just part of VB.NET itself now?

ALSO, how would one add an attribute to the Customer element such that it read like this:

<Customer id="12345"> in the resulting XML

# re: Writing Data from a DataTable to Excel

Friday, October 09, 2009 3:19 PM by noel

try to use the code as it but i get an undeline error on "Customers" name "Customers" is not declared

# re: XML Literals: Creating an XML File

Friday, October 09, 2009 5:59 PM by Deborah Kurata

Hi Jerry -

Thank you for coming by the blog. XML Literals are a feature of VB.NET only.

To add an attribute, the code would look something like this:

Dim customerXml As XElement = _

<customers>

  <%= From c In custList _

      Select <customer id=<%= c.CustomerId %>>

                <LastName><%= c.LastName %></LastName>

                <FirstName><%= c.FirstName %></FirstName>

             </customer> %>

</customers>

Hope this helps.

# re: Writing Data from a DataTable to Excel

Friday, October 09, 2009 6:02 PM by Deborah Kurata

Hi Noel -

Are you referring to this line?

Dim dt As Data.DataTable = Customers.RetrieveAsDataTable

As I mentioned in the description following the code, you can use any DataTable. In my example, the DataTable came from my Customers class. You will have to change the right side of this equation to reference your table from whereever it is.

Hope this helps.

# re: Silicon Valley Code Camp

Saturday, October 10, 2009 7:26 PM by Melinda Xiao

Deborah,

I was in your class lamda expression. really liked it. May I get the slides?  

melinda_x@yahoo.com

Thank you

- Melinda

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 2:11 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: Finding an Item in a Generic List

Sunday, October 11, 2009 2:52 PM by Deborah's Developer MindScape

In this prior post , I detailed how to build lists of things using a generic List<T>. Once you

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 2:56 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 3:30 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: Syntax

Sunday, October 11, 2009 4:02 PM by Deborah's Developer MindScape

This post covers the syntax for lambda expressions. It uses the customer list defined in this prior post

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 5:14 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 5:46 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 6:57 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 6:57 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 6:57 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Lambda Expressions: An Introduction

Sunday, October 11, 2009 7:00 PM by Deborah's Developer MindScape

My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience

# Interesting Finds: October 12, 2009

Monday, October 12, 2009 7:23 AM by Jason Haley

Interesting Finds: October 12, 2009

# re: Lambda Expressions: Finding Differences in Two Lists

Tuesday, October 13, 2009 3:47 AM by Steve

exceptionFunction looks like it's some function that handles Exceptions :p

# WinForms User Controls 101

Tuesday, October 13, 2009 11:44 AM by Deborah's Developer MindScape

The same several questions often come up in the forums regarding the basics of building a user control

# re: Using Object Binding

Tuesday, October 13, 2009 6:38 PM by Nguyen

Good one!

# re: WinForms User Controls 101

Wednesday, October 14, 2009 4:37 AM by Joacim Andersson

You forgot to mention Extender controls, a control that extends another by providing new properties and behavior. The classic example is the ToolTip control which, as soon as you've put on on a form, will extend all other controls with a ToolTip property.

# re: General: Brazil (the Movie)

Wednesday, October 14, 2009 7:49 PM by alex

Maybe you should read up on it a little. This film was extremely important at the time, portraying serious social issues with black humour. Dismissing a film because it is "a little odd" is a little closed minded when it comes to film review.

# re: DAL: Using a Data Provider Factory

Thursday, October 15, 2009 6:08 AM by Volker Schaak

Hi Deborah,

let me first thank you for your work, esp. your "Doing objects..." books. Really good intro for OOP in VB(.net)!

Unfortunatly I've got to put some salt in the generic approach to data access:

1) MS-DBProvider approach doesn't support Oracle-return parameters, that do return a cursor, which is THE way for Oracle-SPROCs to return resultsets. The DBType enumeration doesn't contain a DBType.Cursor or something similar. So, one has to implement something more special inside the DAL...

2) The Oracle Parameter-Format (at least in Ora 9.2) isn't neccessarily the name with : before! Doing ad hoc queries like "SELECT * FROM table WHERE field = :Value" this works, but not with SPROCs! (The ad hoc-query approch counters the generic approch, since it implies NOT to write provider specific SQL-code!)

So that sadly reduces the DBFactory to a semi-generic issue, esp. when using a SPROC approach.

IMHO MS should finish it's work in those areas instead of walking hundreds of new paths, only to realize those are dead ends...

Best wishes and take care

Volker from Germany

# re: General: Brazil (the Movie)

Thursday, October 15, 2009 1:55 PM by Deborah Kurata

Hi Alex -

Thank you for dropping by my blog.

Yes, I assumed it was a very important movie at the time considering its Oscar nomination and interesting social statements. But it was not for me.

And as you may guess, I am a software developer by trade, not a movie reviewer. Just wanted to share my opinion and thoughts.

Thanks for sharing yours as well!

# Populate business object

Friday, October 16, 2009 4:29 AM by Troopers

Could you give us an example for the method :

Retrieve a populated business object using a DataContext

I wish bind a business object on data and I wish my methods return some List<mybusinnessobject>

# re: Writing Data from a DataTable to Excel

Friday, October 16, 2009 5:14 AM by Manu

To  Deborah Kurata

Thanks a lot... I really appreciate your effort..

this blog was really helpful..

# re: Writing Data from a DataTable to Excel

Friday, October 16, 2009 5:17 AM by Manu

 WB.SaveAs(filename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

this code also works.. :: )

# re: Reading Fixed Length Files

Friday, October 16, 2009 10:46 AM by Sri

Hi Deborah

I liked the simplicity of your articles. I had a task to read a tab delimited text file into dataset and was using this code. But my limitation is that I can't create any file on the server i.e. schema.ini. Is there a way to use oledb to readt tab delimited file without using schema.ini file?

# re: Reading Fixed Length Files

Friday, October 16, 2009 11:28 AM by Deborah Kurata

Hi Sri -

Did you see this blog post?

msmvps.com/.../reading-comma-delimited-files-textfieldparser.aspx

Hope this helps.

# re: Reading Fixed Length Files

Friday, October 16, 2009 12:31 PM by Lon Feuerhelm

Deborah,

Great post. This is probably a matter of personal taste but if I were coding this I would define the Customer ID as 8 and the Last Name as 20, I prefer to deal with trailing spaces I've always felt leading spaces are more problematic to deal with when processing data.

# Lambda Expressions: Execution

Friday, October 16, 2009 3:26 PM by Deborah's Developer MindScape

Lambda expressions can be assigned to a delegate variable. The lambda expression is then executed when

# Lambda Expressions: Execution

Friday, October 16, 2009 3:26 PM by Deborah's Developer MindScape

Lambda expressions can be assigned to a delegate variable. The lambda expression is then executed when

# Lambda Expressions: Execution

Friday, October 16, 2009 3:26 PM by Deborah's Developer MindScape

Lambda expressions can be assigned to a delegate variable. The lambda expression is then executed when

# Interesting Finds: October 17, 2009

Saturday, October 17, 2009 6:46 AM by Jason Haley

Interesting Finds: October 17, 2009

# re: Populate business object

Monday, October 19, 2009 3:34 AM by Troopers

Hi,

I create this function to return a List<mybusinnessobject>

public static List<T> ExecuteAndBindToObject<T>(Param pParam)
{
   // Create the return list of T
   List<T> lList = new List<T>();
   // Get the type T and the properties
   Type tType = typeof(T);
   PropertyInfo[] piProperties = tType.GetProperties();
   // Execute the stored procedure
   DataTable dtTable = ExecuteDataTable(pParam);
   // If we found some records
   if(dtTable != null && dtTable.Rows.Count > 1)
   {
      // For each record
      for(int iRow = 0; iRow < dtTable.Rows.Count; iRow++)
      {
         // Create an object of type T
         T oCurrentObject = (T)Activator.CreateInstance(tType);

         // For each property of T
         foreach(PropertyInfo piProperty in piProperties)
         {
            // Get the binding info attribute
            object[] oAttributes = piProperty.GetCustomAttributes(typeof(BindingInfo), true);
            if(oAttributes.Length != 0)
            {
               BindingInfo biInfo = (BindingInfo)oAttributes[0];
               // Get the value in the datasource
               object oValue = dtTable.Rows[iRow][biInfo.SourceFieldName];
               // Set the property value of the current object
               piProperty.SetValue(oCurrentObject, oValue.GetType() ==
                                         typeof(DBNull) ? null : oValue, null);
            }
         }
         // Add the current object
         lList.Add(oCurrentObject);
      }
   }
   // Return the list
   return lList;
}

[AttributeUsage(AttributeTargets.Property, AllowMultiple=false)]
public class BindingInfo:System.Attribute
{
   private string sSourceFieldName;
   public BindingInfo(string sSourceFieldName)
   {
      this.sSourceFieldName = sSourceFieldName;
   }
   public string SourceFieldName
   {
      get { return sSourceFieldName; }
   }
}

NOTE: I reformatted the code - DJK

 

# re: Reading Fixed Length Files

Monday, October 19, 2009 9:20 AM by Sri

Thanks Deborah, I read the suggested post and found that it would be easier to use Schema.ini file. So now I got access to temporarly create schema.ini file and export the tab delimited file to dataset.

This was working great with test data but when I tried with production data. It failed because of datatype issue. Some of the rows have numeric data and some has text in one of the column. So I modified the Schama.ini file to add "Col3=C Text Width 100" but unfortunately I am still getting the same datatype error. I am not sure if Schema.ini is bein read or not? Appreciate your suggestions.

# re: Converting Text to Proper Case

Monday, October 19, 2009 9:02 PM by raveee

Good! But the code could not get me to convert my Heading to either lower or upper.  Any suggestions?

# Anonymous Types: An Introduction

Tuesday, October 20, 2009 11:56 PM by Deborah's Developer MindScape

The last several posts have provided examples of using anonymous types. This post backs up a little and

# Anonymous Types: An Introduction

Tuesday, October 20, 2009 11:56 PM by Deborah's Developer MindScape

The last several posts have provided examples of using anonymous types. This post backs up a little and

# Anonymous Types: An Introduction

Tuesday, October 20, 2009 11:56 PM by Deborah's Developer MindScape

The last several posts have provided examples of using anonymous types. This post backs up a little and

# Anonymous Types: An Introduction

Tuesday, October 20, 2009 11:56 PM by Deborah's Developer MindScape

The last several posts have provided examples of using anonymous types. This post backs up a little and

# re: DAL: DataTable Visualizer

Wednesday, October 21, 2009 5:00 AM by Carine

Thank You so much !! i was lookin 4 it since more than 1 month.. i just found the solution :)

# re: Silicon Valley Code Camp

Wednesday, October 21, 2009 2:05 PM by Deborah Kurata

Hi Melinda -

Thank you for visiting my blog. Glad you liked the talk.

The information from the slides starts here:

msmvps.com/.../lambda-expressions-an-introduction.aspx

Thanks again!

# Unit Testing: An Introduction

Sunday, October 25, 2009 4:04 PM by Deborah's Developer MindScape

If you have Visual Studio 2008 or later and have the Professional Edition or better (NOT the Express

# re: Populating a DataGridView from Xml Data

Sunday, October 25, 2009 5:20 PM by Ciro

Hi Deborah!

This post help me a lot.

Thank you!

# Unit Testing: Execution

Sunday, October 25, 2009 5:50 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Unit Testing: Code Coverage

Sunday, October 25, 2009 6:27 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Unit Testing: Code Coverage

Sunday, October 25, 2009 6:27 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# re: Populating a TreeView Control from XML

Sunday, October 25, 2009 11:24 PM by ExcelMonkey

Deborah, if you only wanted to populate the California portion of the XML tree how would you do this?  I am assuming that you have to take out the first For/Next stmt with <State>.  

   stateNode = ?

   For Each region As XElement In state...<Region>

       regionNode = stateNode.Nodes.Add(region.@name)

       For Each area As XElement In region...<Area>

           regionNode.Nodes.Add(area.@name)

       Next

   Next

Thanks

EM

# re: Unit Testing: An Introduction

Monday, October 26, 2009 4:33 AM by Anon

Hi there,

Isn't it bad practice to use the autogenerated unit tests.  I heard somewhere that it is.

I heard that its best to write the unit test from scratch.

# re: DAL: Using a Data Provider Factory

Monday, October 26, 2009 5:54 AM by SHIVAJI

VB.NET  APPLICATION DEMO WITH SOURCE HAVING BO, DAL, AND UI.

# Interesting Finds: October 26, 2009

Monday, October 26, 2009 7:51 AM by Jason Haley

Interesting Finds: October 26, 2009

# Interesting Finds: October 26, 2009

Monday, October 26, 2009 7:51 AM by Jason Haley

Interesting Finds: October 26, 2009

# Interesting Finds: October 26, 2009

Monday, October 26, 2009 7:51 AM by Jason Haley

Interesting Finds: October 26, 2009

# re: Unit Testing: An Introduction

Monday, October 26, 2009 11:24 AM by Deborah Kurata

Hi Anon -

Thank you for dropping by my blog.

Visual Studio is not really generating your unit test ... only a template for your unit test. You still have to write all of the code to perform the test.

So in my opinion, there is no downside. Think of this generated code as your unit test snippet: you still need to fill in all of the important details.

Hope this helps clarify.

# re: DAL: Using a Data Provider Factory

Monday, October 26, 2009 11:26 AM by Deborah Kurata

Hi Shivaji -

I have an example here:

www.insteptech.com/.../samplecode.htm

Hope this helps.

# re: Populating a TreeView Control from XML

Monday, October 26, 2009 1:16 PM by Deborah Kurata

Hi EM -

I assume this thread is answering your question:

social.msdn.microsoft.com/.../6a9507c8-7c37-4850-abd2-c43252a53c33

# re: Unit Testing: Code Coverage

Tuesday, October 27, 2009 7:22 AM by Patryk Zera

I have VS 2008 Professional, but I don't see Code Coverage in LocalTestRun.testrunconfig (also I don't have Controller And Agent and Web Test options). Do I need test certain projects or install something additional?

# re: Unit Testing: Code Coverage

Tuesday, October 27, 2009 10:48 AM by Deborah Kurata

Hi Patryk -

My mistake. The Professional Edition has the tools for building, executing, and debugging unit tests. However, the code coverage tools are only in the Team System Edition.

I corrected the post.

Thank you *very* much for pointing this out so I could correct this error.

# re: Unit Testing: Execution

Tuesday, October 27, 2009 11:51 AM by B. Clay Shannon

Wow! Unless the computer's date/time was tweaked forward, this article was created just a couple of days ago - usually the dates shown are months if not years in the past.

Anyway, my question is: Can random values be sent to these tests, such as in the case of testing last names, could it be sent a bunch of different strings, such as:

Twain

12345

Clemens

`1!@#

O'Malley

McClintock

l'Raisson

a;fasdkl;jsdfa;jklsdfa

etc.?

I don't know if I will pass this way again, so if you really want me to see a reply, please email it to bcshanno@jcpenney.com

# re: Unit Testing: Execution

Tuesday, October 27, 2009 5:44 PM by Deborah Kurata

Hi B. Clay -

I don't know where you are reading an odd date, but I see 2009-10-25 everywhere (last Sunday). The 15:25:40 is the time (hour, minutes, seconds) Where are you seeing a date in years past?

Regarding your question, yes.  The next article in this series will cover how to test properties in further detail.

Thanks for coming by the blog.

# re: Unit Testing: Code Coverage

Wednesday, October 28, 2009 6:38 AM by Patryk Zera

Thank you for taking your time to investigate this.

# re: Writing Data from a DataTable to Excel

Wednesday, October 28, 2009 2:52 PM by sanjay

Terrific Mate..

# re: TryParse

Thursday, October 29, 2009 8:23 AM by John Dauphine

I found a couple of code posting on a nullable tryparse method.  The code the I came up with is here johndauphine.blogspot.com/.../nullable-tryparse-function-in-c.html.

# re: TryParse

Thursday, October 29, 2009 8:37 AM by John Dauphine

BTW, here is how I call a the function  

NullableParser<double>.TryParse(dataToLoad["foobar"].ToString(),  out  _fooBar );

Where datatoload is a DataRow

# Unit Testing: Testing Properties

Thursday, October 29, 2009 5:01 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Unit Testing: Testing Properties

Thursday, October 29, 2009 5:01 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Unit Testing: Testing Properties

Thursday, October 29, 2009 5:17 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Unit Testing: Exposing Internal/Friend Members

Thursday, October 29, 2009 5:23 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Unit Testing: Exposing Private Members

Thursday, October 29, 2009 6:19 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Unit Testing: Exposing Private Members

Thursday, October 29, 2009 6:19 PM by Deborah's Developer MindScape

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development

# Visual Studio: Clipboard Ring

Thursday, October 29, 2009 7:35 PM by Deborah's Developer MindScape

Way back when we were using Visual Studio 2005, there was a Clipboard Ring tab in the Toolbox. I loved 

# re: Unit Testing: Exposing Private Members

Thursday, October 29, 2009 7:46 PM by CB

Is there something -- the [TestMethod()] attribute, perhaps -- that restricts PrivateObject's use?  

Or can it be used anywhere?

# re: Unit Testing: Exposing Private Members

Friday, October 30, 2009 10:09 AM by Deborah Kurata

Hi CB -

Thank you for visiting the blog.

The PrivateObject is in the following namespace:

Microsoft.VisualStudio.TestTools.UnitTesting

And the description of the class is "Allows test code to call methods and properties on the code under test that would be inaccessible because they are not public. "

I don't think it was meant to be used anywhere else.

And maybe that is a good thing? If a class has private members, it seems that they should *not* be accessed by external code? (Testing being the only exception)?

# re: Unit Testing: Exposing Private Members

Friday, October 30, 2009 2:18 PM by Urs Enzler

The only thing I miss here is a reason why I should call private members directly. If a private property or method cannot be tested by calling other public members or I have a need to test it independantly then the private member should be refactored out to a dedicated class. Otherwise, the Single Responsibility Principle is likely to be violated.

# re: DAL: Using a Data Provider Factory

Sunday, November 01, 2009 2:08 AM by Shiv

Thanks for your post. It was very useful. Just would like to share that, I could also create parameter from DbProviderFactory.CreateParameter() and it created param specific to my provider. This way, I could avoid below switch case...

switch (df.GetType().Name)

                   {

                       case "SqlClientFactory":

...........

# re: RichTextBox Styles

Sunday, November 01, 2009 6:12 AM by Mark Wisecarver

Thanks a bunch Deborah, this will help a lot of developers.

# Unit Testing: An Introduction - Deborah Kurata

Sunday, November 01, 2009 8:35 AM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: Writing Data from a DataTable to Excel

Monday, November 02, 2009 1:52 PM by Chris

This is a nice example of automating Excel via .NET, which I would like to see more of, but this method will be painfully slow for large amounts of data.  Anyone else have "bulk" methods for sending the data in one shot?

I know this can be done with an array, but you must first get from the datatable to the array.  Using a  StreamWriter to go to .csv is also fast, but this file must then be opened in Excel.  It would be nice to have a fast direct method.

# re: DAL: Using a Data Provider Factory

Tuesday, November 03, 2009 10:46 AM by Volker Schaak

Hi Shiv,

the switch/case statement in the DAL-snippet is mainly due to the different naming conventions for DBParameters. The DBFactory.CreateParameter() method won't supply the Parametername with the '@', '?' or (sometimes, not always) ':'.

For that reason a DAL needs to make a difference, here done by switch/case. Another attempt could be to read the DB's Schema, where'll find 'ParameterMarkerFormat'...

Best wishes

Volker

# Social comments and analytics for this post

Friday, November 06, 2009 10:17 AM by uberVU - social comments

This post was mentioned on Twitter by brada: Great post on RIA Services with VB.. http://bit.ly/1eplar

# re: Silverlight, RIA Services, and Your Business Objects

Friday, November 06, 2009 8:02 PM by Robert Martin

I am CEO of a software development company in Australia and I have to say that this is without doubt the single most informative, thorough and extensive .NET blog on the entire Internet. It is so good  I feel almost guilty about getting this for free. Deborah, you are amazing.

# re: Silverlight, RIA Services, and Your Business Objects

Saturday, November 07, 2009 3:46 PM by Deborah Kurata

Hi Robert -

Thank you for the kind words.

They really encourage me to keep going!