The techie in me RSS 2.0
 Saturday, May 17, 2008

If you have worked with strongly typed dataset, it is very likely that you must have faced this annoying exception regularly. The error message will be something like this.

The value for column \'ColumnName\' in table \'TableName\' is DBNull.

With exception type : System.Data.StrongTypingException

Well that's a typical message ain't it ? But interesting part is, if you see the property code in the dataset class it will similar to

get {
    try {
        return ((global::System.String)(this[this.tableName.Column]));
    }
    catch (global::System.InvalidCastException e) {
        throw new global::System.Data.StrongTypingException("The value for column \'Column\' 
                                 in table \'TableName\' is DBNull.", e);
    }
}
set {
    this[this.TableName.Column] = value;
}

Now from the code you can see that, if you are thinking of comparing the field with Dbnull or null or some value still it will give the error. It is a InvalidCast exception.

There is a simple method to solve this issue, when you use the xsd.exe(or VS IDE) to generate the dataset class give a value for the 'null value'

This is how you do it.

1. Add codegen namespace in the scheme

In the xsd file(schema) add the below line to add the namespace immediately after targetnamespace

xmlns:codegen="urn:schemas-microsoft-com:xml-msprop

2. Add the 'null value' to the elements you want to protect from this error.

for ex :

<xs:element name="Column1" codegen:nullValue="-1" type="xs:string" minOccurs="0" />

The bold attribute sets the nullvalue.

 

Thats it, then generate your typed dataset, and you will no longer have the weird exception.

If you really dont want to touch the xsd, there is another way of getting rid of this, the dataset class gives a method 'IsColumnNull', use this method in your code to check if its null :)

The above information is extracted from MS KB article

 

Keep strong typing :)

-Rujith

Saturday, May 17, 2008 1:21:57 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Coding
 Thursday, April 24, 2008

Well, Coding has always been the best part like my job. I really enjoy it, after long time I am coding again, I want to be programmer again. I have been involved in all design discussions, brainstorming sessions for all the complex problems and all those long long sleepy meetings :). But yesterday whole day I was coding, thinking about logic, thinking about shortcuts etc, it was fun , I dono what people sitting near me must have thought about me but I really enjoyed it.

 

Thursday, April 24, 2008 10:14:37 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -

 Tuesday, April 15, 2008

Exporting or import excel data to/from xml is pretty simple and straight forward after office 2003. You dont have to write any code or macros for the straight forward export. I have found an add-in which was very useful for me when I was doing couple of exports.

The good thing about this add-in is you dont have specify any schema to get the data, simply select the range, and select if the first row is the column heading thats it, you get the xml data within couple of clicks. Well its not just that, it can help you to create XSD files for XML maps, rename the <Root> and <Row> elements, or refresh all of the XML maps in a workbook.

I highly recommend this add-in if you are using any kind of xml import or export using Excel 2003.

Read more about the add-in here

 

-Rujith

 

Tuesday, April 15, 2008 3:02:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Office
 Sunday, April 06, 2008

I saw this very useful page for comparison of major features between popular version of Windows mobile.

Its interesting to see that there are not many featues added in 6.1, rather thats why its 6.1 not 7.0 :).

One intresting and much required feature that I noticed in 6.1 is auto pairing with bluetooth headsets. Who ever have had exprience with pairing their headset each time once it goes out of range would appreciate this feature. And this page is very nice to see the quick list of features that you will be intrested in, especially if you already familier with Windows mobile ver 6.0 or 5.0

I am waiting my finger's crossed for my T mobile Vario II update, which should be available here soon

 

-Rujith

Sunday, April 06, 2008 12:33:26 PM (GMT Standard Time, UTC+00:00)  #    Comments [1] -
Windows Mobile
 Wednesday, March 12, 2008

Yes, can you imagine writing code on a white plain board ? Today it was required by me to write C# code on white board using marker :(. It was very tough for me. Lot of syntax errors, wrong methods or properties and on top of all my hand writing. I am glad that they were able to read it.

I started imagining about coding without visual studio. I remember doing HTML  & Java coding using notepad.exe, it was fun isn't it. But now the world has changed lot of new tools to reduce your repetitive task. C'mon you don't want to spend time on remembering all the methods(and their overloads) and properties for String class. Instead of that you can dedicate your thinking towards creating  better design or better code.

Initially it used to be editors, Visual studio is a very good Integrated Development Environment(IDE) , the intellisense feature is an amazing feature, in VS 2008 you have intellisence for ECMA script(Java Script) also. You can always create .NET assemblies without using Visual studio, but can you imagine how much time it is going to take. You need Rapid Development not to take 1 man day to write a code to get some data from database. 

Then you have Application blocks (Enterprise Library) for code reusability. Then you have persistence framework like NHibernate etc for object persistence - for code generation

Now you have software factories for literally creating the entire application :).

See the evolution of coding, from writing code in notepad to generating code using tools(Guidance automation and SW factories), will tools take over my job in future ????? oh my god

 

Rujith

Wednesday, March 12, 2008 5:34:57 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -

 Tuesday, March 11, 2008

I was trying to configure live writer to post to my blog which is set up using DasBlog. Well as all Microsoft products it is very easy to configure, select Blog provider as 'other', give your blog url and user name and password which you use to blog, and click next that's all. All settings will be configured automatically.

Well, you might be wondering what is there to blog about this, there is one important setting in your blog which if you don't set you will get "service disabled Error" while trying to configure the LiveWriter for DasBlog.

In your blog configuration(at you DasBlog) you have to enable the "Blogger/MovableType API", else you will get the Service disabled error in live writer.

Hope it will be useful for at least some one.:)

-Rujith

Tuesday, March 11, 2008 7:02:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -

About me
Name : Rujith Anand Send mail to the author(s)
Archive
<May 2008>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogs I read
Disclaimer

Disclaimer
Postings are provided as is with no warranties, and confer no rights. Opinions expressed here are my own delusions; my employers at best shake their heads and sigh, at worst repudiate the content with extreme prejudice, whenever it manages to appear on their radar.

© Copyright 2012
Rujith Anand

Statistics
Advertisement
All Content © 2012, Rujith Anand