I got error from vb code

Posted by Pavithra under ASP.NET on 1/24/2015 | Points: 10 | Views : 1449 | Status : [Member] | Replies : 1
I inserted the error line code in below:

Sql = "Update details set Deptartment= '" & txtDept.Text & "', tenthMark= '" & txtten.Text & "', zthMark= '" & txttwel.Text & "', Maths= '" & txtmaths.Text & "', Physics= '" & txtphy.Text & "', Chemistry= '" & txtche.Text & "' where Name= '" & txtName.Text & "'"

But I got Error this:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Please any one help to me

Thank You,


Posted by: Sheonarayan on: 1/24/2015 [Administrator] HonoraryPlatinum | Points: 25

This error is because of an object (control) that doesn't have any value or even the control doesn't exists in the context. Ensure that all your textboxes are there on .aspx page and they are named correctly in the code.

On the other side, I would suggest not to use sql statement like above to update/insert/delete/select records from the database instead use parameterized statement as above is prone to SQL Injection and you may loose the entire data if someone tried to inject into your database.

To know how to use parameterized SQL statement to work with database, read this article http://www.dotnetfunda.com/articles/show/2708/3-tier-architecture-in-aspnet-a-complete-article first code snippet (PersonDAL.cs).


Sheo Narayan

Pavithra, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response