Answered by:
ASP Dot Net

Question
-
I am Using ASP Dot Net-2.0 with SQL server-2005
in Save button i have both condition are Insert and update condition
here like the code
Save_click()
{
BLClass objBL=new BLClass();
int Result;
Switch(ViewState["Mode"].ToString())
{
case"New":
Result=objBL.InsertRecords(txtName.text,txtAddress.text);
break;
case"Edit":
Result=objBL.UpdateRecords(ViewState["ID"].ToString(),txtName.text,txtAddress.text);
break;
}
Dataset ds=new Dataset();
ds=objBL.SelectRecords();
gv.DataSource=ds.Tables[0].DefaultView;
gv.DataBind();
}
When i do this i got Error is Null Reference was unhandeled by the user code pls give the help for this code i need to use now
- Moved by SamAgain Friday, August 6, 2010 7:28 AM (From:.NET Base Class Library)
Wednesday, July 14, 2010 4:59 AM
Answers
-
Hi Naveen,
Check whether the ViewState["Mode"] has any value. There is a possibility of this exception being raised when the value is null and you try to use ToString() function on that, So check whether ViewState["Mode"] is having any value at all.
This question is specific to ASP.Net, Please post it at forums.asp.net
Thanks & Regards,
Sai Pavan
[Please mark the post as answer if it answers your question]
- Edited by Sai Pavan Viswanath Wednesday, July 14, 2010 6:28 AM updated the signature
- Proposed as answer by Chethan Kamath Wednesday, July 14, 2010 6:41 AM
- Marked as answer by SamAgain Wednesday, July 14, 2010 10:07 AM
Wednesday, July 14, 2010 5:10 AM
All replies
-
The objBL.SelectRecords() might be returning a null data object. when you try to set it as the datasource of the gridview, it will give a null reference.
P.S: For any questions specific to asp.net, please post at www.asp.net/forums
Ganesh Ranganathan
[Please mark the post as answer if it answers your question]
blog.ganeshzone.netWednesday, July 14, 2010 5:02 AM -
Hi Naveen,
Check whether the ViewState["Mode"] has any value. There is a possibility of this exception being raised when the value is null and you try to use ToString() function on that, So check whether ViewState["Mode"] is having any value at all.
This question is specific to ASP.Net, Please post it at forums.asp.net
Thanks & Regards,
Sai Pavan
[Please mark the post as answer if it answers your question]
- Edited by Sai Pavan Viswanath Wednesday, July 14, 2010 6:28 AM updated the signature
- Proposed as answer by Chethan Kamath Wednesday, July 14, 2010 6:41 AM
- Marked as answer by SamAgain Wednesday, July 14, 2010 10:07 AM
Wednesday, July 14, 2010 5:10 AM -
Hi,
Thanks for your post. Please consider http://forums.asp.net as a better option.
Please mark the right answer at right time.
Thanks,
SamFriday, August 6, 2010 7:28 AM