Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void btnSearch_Click(object sender, EventArgs e)
    {
        Library lib = new Library();
        
        string sEmp_name = "";
        


        if (ddrCompany.SelectedValue.Trim() == "MEHTASCL")
        {
         sEmp_name = txtEmpname.Text;
        }
        else if (ddrCompany.SelectedValue.Trim() == "MEHTAGSC")
        {
            sEmp_name = txtEmpname.Text;
        }

        
            DataTable dtempdetail = new DataTable();
            dtempdetail = lib.getemployDetail(sCompany, sEmp_name);
                if(dtempdetail.Rows.Count > 0)
                {
                    grdJobHistory.DataSource = dtempdetail;
                    grdJobHistory.DataBind();
                }

    }
Posted
Updated 24-May-10 1:29am
v2
Comments
Johnny J. 24-May-10 7:25am    
What line is creating the error?

Either dtempdetail or the Rows collection are null. Since only you can run this under the debugger, it's up to you to determine which is null and how to fix it. I would probably do this:

dtempdetail = lib.getemployDetail(sCompany, sEmp_name);
<big>if (dtempdetail != null)
{</big>
    if (dtempdetail.Rows.Count > 0)
    {
        grdJobHistory.DataSource = dtempdetail;
        grdJobHistory.DataBind();
    }
<big>}</big>
 
Share this answer
 
v2
if(dtempdetail.Rows.Count > 0)

above line is creating the error....
 
Share this answer
 
Comments
Christian Graus 24-May-10 7:38am    
Don;'t push 'answer' to add detail, edit your post. As John said, you set this variable to a new DataTable because you know nothing about programming. That instance is lost right away, and if the method you call can return null, you need to check for it.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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