2

I am using the the following code to fill the dataset

public static DataSet GetDataSetBySP(string spName)
    {
        try
        {
            using (SqlConnection conn = new SqlConnection(ConnString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = spName;
                cmd.CommandTimeout = 60;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);

                conn.Close();
                return ds;
            }
        }
        catch
        {
            return null;
        }
    }

at the first time i am calling the function i am getting only first table filled with data and other will look like this enter image description here

and the error in Data Visualizer is like

DataSet Visualizer

Unhandled exception has occurred in a component in your application.If you click Continue,the application will ignore this error and attempt to continue.

Object referance not set to an instance of an object


See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at EnhancedDataSetVisualizer.VisualizerCommunicator.GetTableCellValue(Int32 rowIndex, Int32 colIndex)
   at EnhancedDataSetVisualizer.DataSetForm.dataGridView_CellValueNeeded(Object sender, DataGridViewCellValueEventArgs e)
   at System.Windows.Forms.DataGridView.OnCellValueNeeded(DataGridViewCellValueEventArgs e)
   at System.Windows.Forms.DataGridView.OnCellValueNeeded(Int32 columnIndex, Int32 rowIndex)
   at System.Windows.Forms.DataGridViewCell.GetValue(Int32 rowIndex)
   at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
   at System.Windows.Forms.DataGridViewRow.PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
   at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
   at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)
   at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
   at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Microsoft.VisualStudio.CommonIDE
    Assembly Version: 9.0.0.0
    Win32 Version: 9.0.30729.1
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.CommonIDE/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.CommonIDE.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.VisualStudio.DebuggerVisualizers
    Assembly Version: 9.0.0.0
    Win32 Version: 9.0.30729.1
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.DebuggerVisualizers/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.DebuggerVisualizers.dll
----------------------------------------
Microsoft.VisualStudio.Debugger.DataSetVisualizer
    Assembly Version: 9.0.0.0
    Win32 Version: 9.0.30729.1
    CodeBase: file:///C:/Program%20Files/Microsoft%20Visual%20Studio%209.0/Common7/Packages/Debugger/Visualizers/Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

can anybody tell me why i am seeing this? But second time when i am refreshing my aspx page i am getting all the tables proper with proper data.

thanks in advance

New Edit

Hi all,thanks for quick reply. but i am not getting any error in the catch.The Dataset fill success fully,even the data of first table i am getting proper,but rest of the 2 tables i am finding this exception not with the code.

Latest Update

Also I found in another test that,the Dataset Visualizer not showing the datatable mote that one.It contains records/tables but still its showing the above one error.May be due to some problem

gofor.net
  • 4,218
  • 10
  • 43
  • 65

3 Answers3

0

At a guess, there is a good chance there is an exception occurring and since you have...

     catch
    {
        return null;
    }

The UI cannot render a null DataSet. I recommend checking if an exception is being raised and if so look at its message to see if there is an issue with connecting to the DB or filling the DataSet with records.

EDIT

Since you confrm there is no exception in the catch block I did a quick look around and there might be an issue with Visual Studio. There is an MSDN forum entry that looks like the same issue.

There is also a connect issue logged and they say the issue is fixed in Visual Studio 2010, are you able to reproduce this on 2010 (if you have access to it?)

aqwert
  • 10,559
  • 2
  • 41
  • 61
0

Are you checking if returned value is not null? There might be some exception in your function. I would remake catch part to

    catch
    {
        return new DataSet();
    }

or even better, i would make some Error event that would show some messagebox with error.

    catch(Exception exc)
    {
        Error(exc);
        return new DataSet();
    }
Milan Halada
  • 1,943
  • 18
  • 28
0

My guess is that it's something to do with this:

catch
{
    return null;
}

That means that whatever goes wrong, you'll ignore the problem (not even logging it) and just return null. Anything which tries to use the return value without checking for nullity will give the exception you've shown.

You should never have this sort of blanket "catch all and ignore" handler. If you really want to catch all exceptions (which can be reasonable at the root of a call stack) then you should always log the exception - and at that point you shouldn't be trying to do any more work.

In this case, you should probably have an exception handler higher up, but not catch the exception here at all - let it bubble up the stack, but handle the exception at a higher level by aborting the current user action. Pretending that nothing went wrong, but giving a return value which clearly can't be handled at the moment, is not a good idea.

I would urge you not to return an empty DataSet either - I would say it's probably just not appropriate to have any error "handling" here, as you don't really know how to handle it.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194