Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I'm getting the above mentioned error when bing the tabel to gridview.


Here is my code:

C#
public void BindLCLGrid()
{
UPLCL.Update();
string SFRID = TXTSRFID.Text;
<pre>var LCL = from C in DB.TB_TransSeaLCLs
               where C.tSLC_NUIsActive == 1 && C.tSLC_tSEA_NUPKId == mobjGenlib.ConvertLon(SFRID)
              select new { tSLC_NUPKId = C.tSLC_NUPKId, tSLC_tSEA_NUPKId = C.tSLC_tSEA_NUPKId, tSLC_VCVolume = C.tSLC_VCVolume, tSLC_mUOM_NUPKId = C.tSLC_mUOM_NUPKId, 	 	  tSLC_VCBuyRate = C.tSLC_VCBuyRate, tSLC_VCSellRate =C.tSLC_VCSellRate };
dgLCL.DataSource = LCL;
dgLCL.DataBind();
}


i'm Getting error iv "var LCL ..............."
Can anyone plesase help me to resolve this :(

Code block corrected
Posted
Updated 15-Mar-14 3:56am
v2

Debug and step through your source code.
You will get to the exact line where one of your objects is null and this error is being thrown.
 
Share this answer
 


Add a try-catch to your code, as in


C#
public void BindLCLGrid()
    {

    try
        {
        UPLCL.Update();
        string SFRID = TXTSRFID.Text;
        var LCL = from C in DB.TB_TransSeaLCLs
                  where C.tSLC_NUIsActive == 1 && 
                        C.tSLC_tSEA_NUPKId == 
                            mobjGenlib.ConvertLon(SFRID)
                  select new { 
                        tSLC_NUPKId      = C.tSLC_NUPKId, 
                        tSLC_tSEA_NUPKId = C.tSLC_tSEA_NUPKId, 
                        tSLC_VCVolume    = C.tSLC_VCVolume, 
                        tSLC_mUOM_NUPKId = C.tSLC_mUOM_NUPKId,
                        tSLC_VCBuyRate   = C.tSLC_VCBuyRate, 
                        tSLC_VCSellRate  = C.tSLC_VCSellRate };
        dgLCL.DataSource = LCL;
        dgLCL.DataBind();
        }
    catch ( Exception ex )
        {
        MessageBox.Show ( ex.Message +
                          Environment.NewLine +
                          ex.StackTrace );
        }
    } 


When the exception occurs, the MessageBox will display a large amount of useful information.



Hope that helps.

 
Share this answer
 
This means one of your variables is null, run the code in the debugger and move your mouse over each variable (a tooltip will appear) to see which one it is and work your way back to fix it.
 
Share this answer
 
Comments
[no name] 15-Mar-14 8:33am    
I have checked in Database for SFRID(id is - 36) none of the values seems to be null.
Somewhere in your link expression you have a null value.

My first check would be either the DB or the TB_TranSeaLCLs variables.

Put hem in seperate variables and step through your code in the debugger to check their values.
 
Share this answer
 
Comments
[no name] 15-Mar-14 8:40am    
ok will try
hi
i used my code in below way it works fine..
i missed using
using (LQTransSeaFreightDataContext DB = new LQTransSeaFreightDataContext())
once included it works gud..

thanks for all who helped me
C#
public void BindLCLGrid()
       {
           try
           {
               UPLCL.Update();
               string SFRID = TXTSRFID.Text;
               using (LQTransSeaFreightDataContext DB = new LQTransSeaFreightDataContext())
               {
                   var LCL = from C in DB.TB_TransSeaLCLs
                             where C.tSLC_NUIsActive == 1 && C.tSLC_tSEA_NUPKId == mobjGenlib.ConvertInt(SFRID)
                             select new { tSLC_NUPKId = C.tSLC_NUPKId, tSLC_tSEA_NUPKId = C.tSLC_tSEA_NUPKId, tSLC_VCVolume = C.tSLC_VCVolume, tSLC_mUOM_NUPKId = C.tSLC_mUOM_NUPKId, tSLC_VCBuyRate = C.tSLC_VCBuyRate, tSLC_VCSellRate = C.tSLC_VCSellRate };
                   dgLCL.DataSource = LCL;
                   dgLCL.DataBind();
               }
           }
           catch (Exception ex)
           {

           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900