D
Dave Cooke via .NET 247
Hi all,
I know I am going to kick myself but I have run into a bit of a brick wall and I need some help before I loose the rest of my hair.
All I want to do is insert a new row of data into a access database from a vb.net app I'm writing.
I have read so many forums today and I think I must be missing something really basic.
I have a database with a table in it called Flights.
The columns in the database are:
CellInfo type=string
Flightdate type=dateTime
FlightTime type=int
Key type=int
recordNum autonumber, primarykey
WhyComment type=string
I have created a OleDbDataAdapter1, and Dataset1 to this database.
With my code all I am doing at this stage is trying to insert the word "Test"
into the column "WhyComment" when I click a button.
Heres my code:
***************************************
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Fill Dataset
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
'Assign variables
Dim myNewRow As DataSet1.FlightsRow
Dim myDataset1 As DataSet1
Dim FlightsTable As DataSet1.FlightsDataTable
'Insert the word test into the colum "WhyComment" in table "Flights
'in the database.
'WhyComment is a string table
myNewRow = myDataset1.Flights.NewRow
'The above row is where it errors out with this error:
'An unhandled exception of type 'System.NullReferenceException' occurred
'in DatabaseInserts.exe
'
'Additional information: Object reference not set to an instance of an object
myNewRow("WhyComment") = "Test"
myDataset1.Tables("WhyComment").Rows.Add(myNewRow)
'update Database
OleDbDataAdapter1.Update(DataSet11)
MessageBox.Show("Database updated!")
End Sub
****************************************
Anyones help would be appreciated.
Cheers Dave
I know I am going to kick myself but I have run into a bit of a brick wall and I need some help before I loose the rest of my hair.
All I want to do is insert a new row of data into a access database from a vb.net app I'm writing.
I have read so many forums today and I think I must be missing something really basic.
I have a database with a table in it called Flights.
The columns in the database are:
CellInfo type=string
Flightdate type=dateTime
FlightTime type=int
Key type=int
recordNum autonumber, primarykey
WhyComment type=string
I have created a OleDbDataAdapter1, and Dataset1 to this database.
With my code all I am doing at this stage is trying to insert the word "Test"
into the column "WhyComment" when I click a button.
Heres my code:
***************************************
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Fill Dataset
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
'Assign variables
Dim myNewRow As DataSet1.FlightsRow
Dim myDataset1 As DataSet1
Dim FlightsTable As DataSet1.FlightsDataTable
'Insert the word test into the colum "WhyComment" in table "Flights
'in the database.
'WhyComment is a string table
myNewRow = myDataset1.Flights.NewRow
'The above row is where it errors out with this error:
'An unhandled exception of type 'System.NullReferenceException' occurred
'in DatabaseInserts.exe
'
'Additional information: Object reference not set to an instance of an object
myNewRow("WhyComment") = "Test"
myDataset1.Tables("WhyComment").Rows.Add(myNewRow)
'update Database
OleDbDataAdapter1.Update(DataSet11)
MessageBox.Show("Database updated!")
End Sub
****************************************
Anyones help would be appreciated.
Cheers Dave