TAGS :Viewed: 15 - Published at: a few seconds ago

[ ASP.NET Website display wrong data ]

I built a web application using ASP.NET, data stored at SQL Server 2008.

The application is running ok, but once a couple of day the application displays wrong data and i get error when i enter some pages. system return to normal work after 5 minutes by it self.

can someone give a clue what is the problem?

I'm getting error on lines which try to take data from retrieved DataTable: like:

txtbx_contact_fullname.Text = dt_contact.Rows[0]["Contact_Fullname"].ToString();

or

lbl_Creation_datetime.Text = dt_YC_Last_Transaction.Rows[0]["Creation_datetime"].ToString();

usually these lines works perfect, and there is no reason that the datatable will return empty. the error i get is: Column 'xxxxx' does not belong to table.

The Query that retrieve the data is:

SELECT [Request ID],[Creation Date],[Request Status],[Contact Fullname],[Start Date],[Start Time],[End Date],[End Time],[Work Mode],[Comments],[HPM Points],[FA Points]
FROM  dbo.vw_All_Requests
WHERE [Request Status] = @YellowCard_Status
ORDER BY [Creation Date] DESC

From some reason some columns do not get back..

Answer 1


txtbx_contact_fullname.Text = dt_contact.Rows[0]["Contact Fullname"].ToString();
lbl_Creation_datetime.Text = dt_YC_Last_Transaction.Rows[0]["Creation datetime"].ToString();

Answer 2


you column name in asp.net code has _ for example full_name but in sql query it does not have _, i don't know you've assigned names to your datatable or not but give attention to this issue ...

Answer 3


if you code is correct. you are calling Creation_datetime from .NET code, but in SQL you have no such column, what you do have is a Creation date only (from your SELECT query).

so, to fix your problem, all you need to do is change

dt_YC_Last_Transaction.Rows[0]["Creation_datetime"]

to

dt_YC_Last_Transaction.Rows[0]["Creation_date"]

after the issue is fixed, you should learn a better way to query the database using explicit names, for example, using objects instead calling the string value... You should learn a bit of Entity Framework and Linq, it will improve your code a lot.