hi
i have page to edit data in sql data base, one of the data is photo
when i select new photo and click update everything working fine , but when i dont choose photo i get this error below :
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 80: cmd.Parameters.AddWithValue("@Emp_Gender", rblGender.SelectedValue);
Line 81: //cmd.Parameters.AddWithValue("@Emp_POB", ddlPOB.SelectedValue);
Line 82: cmd.Parameters.AddWithValue("@Emp_Photo", Session["Photo_Path"].ToString());
Line 83: con.Open();
Line 84: //SqlDataReader V = cmd.ExecuteReader();
Source File: e:\MyTestWebSite\Admin\EmployeeList.aspx.cs Line: 82
the code of my page is like below:
<asp:Panel ID="pnlEmployee" runat="server" Visible="false">
<table class="auto-style1">
<tr>
<td class="auto-style2">Employee Full Name :</td>
<td class="auto-style3">
<asp:TextBox ID="txtFullName" runat="server"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">Gender:</td>
<td class="auto-style3">
<asp:RadioButtonList runat="server" ID="rblGender" AutoPostBack="true">
<asp:ListItem Text="Male" Value="Male"></asp:ListItem>
<asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td class="auto-style3"> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">Place Of Birth</td>
<td class="auto-style3">
<asp:DropDownList ID="ddlPOB" runat="server" Height="16px" Width="117px">
</asp:DropDownList>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">Employee Photo</td>
<td class="auto-style3">
<asp:FileUpload ID="fuPhoto" runat="server" />
</td>
<td class="auto-style3" rowspan="4">
<asp:Image ID="Emp_img" runat="server" Height="139px" ImageUrl="~/img/emp_img.png" Width="147px" />
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click1" Text="Upload Photo" />
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:Button ID="btnEdit" runat="server" Text="Edit Employee" OnClick="btnEdit_Click" />
</td>
<td class="auto-style3">
</td>
</tr>
</table>
</asp:Panel>
and the code behine the page is like below :
protected void btnEdit_Click(object sender, EventArgs e)
{
Session["Grid_ID"] = gvEmpList.SelectedDataKey.Value;
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SP_EditEmpDetails";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Emp_Name", txtFullName.Text);
cmd.Parameters.AddWithValue("@Emp_ID", Convert.ToInt32(Session["Grid_ID"]));
cmd.Parameters.AddWithValue("@Emp_Gender", rblGender.SelectedValue);
//cmd.Parameters.AddWithValue("@Emp_POB", ddlPOB.SelectedValue);
cmd.Parameters.AddWithValue("@Emp_Photo", Session["Photo_Path"].ToString());
con.Open();
//SqlDataReader V = cmd.ExecuteReader();
cmd.ExecuteNonQuery();
lblmsg.Text = "employee updated!!";
con.Close();
gvEmpList.DataBind();
}