Can't insert row
I tried to insert a row using code that worked perfectly in vs 2003.
Included is some of the code:
Dim pid As Integer = CInt(Me.ParentIDLabel1.Text)
Dim title As String = Me.TitleTextBox.Text
Dim ttext As String = Me.txtGeneralText.Text
Dim iss As Integer = Me.IssuerComboBox.SelectedValue
and so on for 12 of 13 fields, not including the autoincrementing key index
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\HasbaraSample.mdb;Persist Security Info=True")
cn.Open()
Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Topics", cn)
da.InsertCommand = New OleDbCommand("INSERT INTO Topics(ParentID, Title, TopicText, Issuer, BeginText, Length, TopicDate, DateType, PointOfView, ContentRights, Publisher, Active) Values(?,?,?,?,?,?,?,?,?,?,?,?)")
da.InsertCommand.Connection = cn
da.InsertCommand.Parameters.Add("@ParentID", OleDb.OleDbType.Integer, 0, "ParentID")
da.InsertCommand.Parameters.Add("@Title", OleDb.OleDbType.VarWChar, 16, "Title")
and so on for each parameter
AddHandler da.RowUpdated, AddressOf OnRowUpDated
Dim ds As New DataSet("ds1")
da.Fill(ds, "Topics")
Dim dtbl As DataTable
dtbl = ds.Tables(0)
Dim newRow As DataRow = dtbl.NewRow()
newRow("ParentID") = pid
newRow("Title") = title
newRow("TopicText") = ttext
and so on for each parameter
dtbl.Rows.Add(newRow)
da.Update(ds, "Topics")
This worked in vs studio 2003. I've seen it recommended in these forums elsewhere. However I received the following error:
system.InvalidOperationException
execute scalar: connection property has not been intialized
line238
which is da.Update(ds, "Topics")
So then I tried: da.UpdateCommand.Connection = cn
which produced the following error:
system.NullReferenceException
Object reference not set to an instance of an object.
line 238
which is: da.UpdateCommand.Connection = cn
Is there any help out there?
dennist

