.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

VB6 Conversion to VB.net Wrapper to prevent Null Exceptions

Posted By:      Posted Date: September 14, 2010    Points: 0   Category :.NET Framework
Thanks for reading this. We are converting a large VB6 application to VB.net. The problem we have all over the code is the .NET converter did not "reorder" the "IF" and other statements in the code to stop execution when a DBNull value exists.  For example, we have code like this all over the place. "If rRow.Item("av_election_id") > 0 And (rRow.Item("Challenged") <> "SUSPD" Or IsDBNull(rRow.Item("Challenged"))) Then" This causes a error when "rRow.Item("Challenged") is dbnull The line of code below corrects this issue but we have thousands of lines of code to reorder and refactor.  If   dtAVVoterRow.Rows(0)("av_election_id") > 0 And (IsDBNull(dtAVVoterRow.Rows(0)("Challenged")) OrElse dtAVVoterRow.Rows(0)("Challenged") <> "SUSPD") Then My question is does anyone have any idea of creating a wrapper class or something to allow us to keep the first example of code above where it will not throw an error when encountering a Null value?  I don't know if a wrapper that reordered the If statements, or captures the error but continues the execution somehow? I appreciate any help.  THanks!  

View Complete Post

More Related Resource Links

How to prevent automatic conversion from .CSV to .XLS

Hi, I have a web page which generates a .CSV file based on some user input. When this file is downloaded by the user, the file is being automatically converted to .XLS. Any idea how I can prevent this? For example, I am redirecting the user to the URL of the generated file, like below URL: http://localhost/reports/Work/aa.csv But the download window appears to download "aa.xls"!

How to get more information about the exceptions that can happen in SharePoint 2010 projects?

In case there is an exception anywhere in the SharePoint 2010 project (most common place an exception would happen is during deployment of your SharePoint project, custom deployment configuration or custom deployment steps), there's a registry key EnableDiagnostics available for you to use.

Program for Format Conversion of An Image

.NET provides extensive support for image conversion. Any image can be processed from one format to another. Most common formats to which .NET have support for are .BMP, .EMF, .GIF, .ICO, .JPG, .PNG, .TIF and .WMF.

Conversion of text files from ANSI to UTF-8

reading and writing text files in ANSI format and
writing html-files in Charset ISO-8859-1 (Western Europe).

How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

WebMatrix conversion failed when converting from a character string to uniqueidentifier?


I am trying to retrieve xml from a small function in my .cshtml page. Its throwing me an error. This however, runs fine in a console/form environment.

It takes 3 parameters and 1 exception.

myDll.GetXML(year, username, uniqueidentifier, out ex);

When I run this page I get the error, "Conversion failed when converting from a character string to uniqueidentifier."

Or a stack of.

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting from a character string to uniqueidentifier.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

   at System.Data.SqlClient.SqlDataReader.get_MetaData()

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBeha

Users getting logged out because HttpContext.Current is null


We've  been trying to fix this one for a couple years, and I'm just out of ideas, so any help is really appreciated!

We've got a fairly large, complex web application that uses Forms Authentication to authenticate users.  Throughout the application we store and retrieve information about users in the Session object, and in some cases in cookies.  In a couple places we check for the existence of the context, and if it's null we send the user back to the login page to re-establish the session. 

Just a quick run-down of this web app: C#, .NET 3.5, IIS 6, ASP.NET State Service to manage session

As for the session timer, we use our own home-grown timer, which is basically a client-side timer, which is backed up by a check to the SQL database to see when their last activity was.  This seems to work well for us.  It's not perfect, but it allows us to notify the user before the session times out, and allows us to be certain we're not logging a user out before their 60 minutes of inactivity is up.

What's happening is that certain users are being logged out after just a few minutes.  We've eliminated the timer as a cause and believe what's happening is the HttpContext.Current is null, so the user is logged out.  We do not know why the HttpContext.Current is null, and I underst

C# conversion to VB and properties


I am trying to implement image caching for a web application and I found some code on the Internet that implements an HttpHandler that does this. The code was in C# and since my web app is written in VB, I decided to convert the code to VB. I managed to convert everything except the following code (in bold):

public class FileExtensionCollection : ConfigurationElementCollection
        public override ConfigurationElementCollectionType CollectionType
                return ConfigurationElementCollectionType.AddRemoveClearMap;

        public FileExtension this[int index]
            get { return (FileExtension)BaseGet(index); }

Handling external C++ exceptions


Hi. I'm working in a application that uses an external .Dll developed in C++ language. According the business rule, the .Dll can throws one exception if it found a error. My question is if it's possible handle or catch a exception throwed by the C++ dll? The try/catch doesn't works. Bellow there's the code I'm using to call the C++ dll.

        public extern static IntPtr LoadLibrary(string lpLibFileName);

        [DllImport("kernel32", CharSet = CharSet.Ansi)]
        public extern static IntPtr GetProcAddress(IntPtr hLibModule, string procName);

        public extern static bool FreeLibrary(IntPtr hLibModule);

        private delegate void DllMethodCallBack(string param1, string param2);

        public void CallDllMethod(string param1, string param2)

Conversion of List to DataTable and ViceVersa


hi ,

           Iam having a requirement where I wil get datatable or Dataview from the DataAccessLayer I need to convert them into GanaricList of entites and ViceVersa from GenericList to Datatable or DataView.

             I tried it but I cant. Can anybody help me out.

'element.className' is null or not an object



I just downloaded the project, compiled it and ran it right out of the box and when I put the mouse pointer over or remove the mouse pointer from either MenuItem in the menu demo, I generate this error:

'element.className' is null or not an object

It points to this javascript method:

updateClassName: function(operation, element, name, value) {
        this[operation + 'String'](
                function() {
                    return element.className;
                function(newValue) {
                    element.className = newValue;

.NET Matters: Aggregating Exceptions


Exceptions in .NET are the fundamental mechanism by which errors and other exceptional conditions are communicated. This month's column provides information about how to aggregate exceptions to help manage a variety of scenarios in which multiple exceptions might result from one operation, including scenarios involving parallelism and concurrency.

Stephen Toub

MSDN Magazine August 2009

CLR Inside Out: Handling Corrupted State Exceptions


There's a danger in using one-size-fits-all exception handling, and you need to know how to avoid it by being as specific as possible about how you handle errors.

Andrew Pardoe

MSDN Magazine February 2009

Toolbox: Live Chat, Code Conversion, Multiple Monitors, and More


This month, more of the tools you need to get your job done.

Scott Mitchell

MSDN Magazine December 2007

Debug Leaky Apps: Identify And Prevent Memory Leaks In Managed Code


When is the .NET Garbage Collector unable to reclaim memory? The answer might surprise you. Stay tuned.

James Kovacs

MSDN Magazine January 2007

Bugslayer: Minidumps for Specific Exceptions


This installment of Bugslayer covers the use of ADPlus to create a minidump of your Microsoft .NET Framework 2.0 pro¬cesses on specific exceptions.

John Robbins

MSDN Magazine November 2006

.NET Profiling: Write Profilers With Ease Using High-Level Wrapper Classes


Here Joachim H. Fröhlich and Reinhard Wolfinger show you how to get all the great functionality of the .NET Profiling API the easy way, with custom wrappers.

Joachim H. Fröhlich and Reinhard Wolfinger

MSDN Magazine April 2006

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend