Last post Oct 28, 2010 03:02 PM by D J
Oct 28, 2010 02:19 PM|uhmmm81|LINK
I want to make a data entry page for keeping track of vacancies in apartment buildings. This will get updated on the last day of every month. There are 8 people who will be responsible for inputing the data and they each have about 10 buildings. I would
like to have a drop down list at the top of the page where they can select their name, and a textbox where they can enter the date. After they enter this information, I would like a gridview to appear that is populated with all of the buildings that belong
to the individual. The gridview will have 3 columns (An edit button, Building Name, # of Vacancies). All they will have to do is hit edit, type in the number of vacancies and hit update.
This will be kept in one table of a database. It will have 3 columns (Building, Date, Vacancies). The problem that I have is after they select their name and enter the date, the gridview will not show up because no records have been inserted into the database
yet. The Select statement for the gridview is ("Select Building, Date, Vacancies FROM tblVacancies WHERE Date = @Date").
So I'm thinking that after they select their name, and enter the date that the program will have to check to see if a record exists for each building on that date, and if it doesn't then it will insert a record into the database. After that the gridview
will be databound. And all of the records will show up to be edited.
Is this the correct way to go about this situation? And if it is, what is the easiest way to check for records and insert records if they don't exist?
Oct 28, 2010 02:44 PM|TabAlleman|LINK
I would just programmatically add a row to the gridview if the select doesn't return any records.
Oct 28, 2010 03:02 PM|D J|LINK
You can do this in this way.
1) After inserting datail first get data for the selected user and Date and this data will be in a DataTable dt.
2) There may be records in it or not (Its your issue). Find the count of rows in it as int rowExists = dt.Rows.Count
3) Now do a loop for 10 - rowExists as for(int i = 0; i < 10 - rowExists; i++)
4) Add blank rows in That table dt with the selected date
5) Now you have total 10 so when you will bind grid with it you will get all rows.
You may also use List instead of DataTable.
Hope it helps