I have an application that I'm currently writing that takes the selected date from a calendar control and populates a datatable with bookings for that date from an access database. The problem I have is that there are not always bookings made so sometimes the datatable contains no rows, if I then try to add a row I get the following error.
System.NullReferenceException: Object reference not set to an instance of an object.
This I assume is because the datatable has a row count of 0. the question is how do I get around this problem, is there a way to add new rows to an empty data Table ?
The code for adding the row is as follows:
VB Code:
Dim objDataRow As DataRow objDataRow=objDataSet.Tables("Bookings").NewRow objDataRow.Item("Aircraft")=aircraft objDataRow.Item("Date")=myDate objDataRow.Item("Name")=txtName.Text objDataRow.Item("Duration")=txtDuration.Text objDataSet.Tables("Bookings").Rows.Add(objDataRow) objBookingDA.Update(objDataSet,"Bookings")




Reply With Quote