DH
I have been fiddling with adding rows and records
i think u might be looking for this..so if im wrong...i appologize for the
post.
I think you might be missing the fill command on the data table ?
Both codes work below... let me know if they help... and if they do, since i
dont know
the terminology, could ya let me know what you did wrong.
Would help me learn if I run into it as well.
Thanks
Miro
-Below is 2 pieces of code... 1 was given by newsgroup that got me started,
the other
is the "long" way of doing it without sql.
================code
Sub AddInitialRecords()
''''Add a quick Record thru SQL - given by Newsgroup...
''''Dim myConnectionString As String = _
''''"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
''''SystemFileDB & FileDBExtension
''''Dim myConnection As New OleDbConnection(myConnectionString)
''''myConnection.Open()
''''Dim myCommand As New OleDbCommand("INSERT INTO DBVersion
(CurVersion) VALUES (?)", _
'''' myConnection)
''''myCommand.Parameters.Add("Param1", OleDbType.VarChar, 50).Value
= "2.00"
''''myCommand.ExecuteNonQuery()
''''myCommand.Dispose()
''''myConnection.Close()
'Add a record the long way thru normal statements.
Dim cnADONetConnection As New OleDb.OleDbConnection()
Dim myConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
SystemFileDB & FileDBExtension
cnADONetConnection.ConnectionString = myConnectionString
cnADONetConnection.Open()
Dim daDataAdapter As New OleDb.OleDbDataAdapter()
daDataAdapter = _
New OleDb.OleDbDataAdapter("Select * From DBVersion",
cnADONetConnection)
Dim cbCommandBuilder As OleDb.OleDbCommandBuilder
cbCommandBuilder = New OleDb.OleDbCommandBuilder(daDataAdapter)
Dim dtVersion As New DataTable()
Dim dtRowPosition As Integer = 0 ' i dont think i use this anywhere
but later i will
'Fill with data
daDataAdapter.Fill(dtVersion)
Dim NoOfRecs As Integer = 0
'Go to first row
Dim rwVersion As DataRow '= dtVersion.Rows(0)
NoOfRecs = dtVersion.Rows.Count()
If NoOfRecs = 0 Then
MsgBox("no recs")
rwVersion = dtVersion.NewRow()
rwVersion("CurVersion") = "3.33"
dtVersion.Rows.Add(rwVersion)
daDataAdapter.Update(dtVersion)
Debug.WriteLine("added record - " +
dtVersion.Rows(dtVersion.Rows.Count - 1)("CurVersion").ToString)
Else
MsgBox("there are recs")
rwVersion = dtVersion.Rows(0)
Debug.WriteLine("read record - " + _
rwVersion("CurVersion").GetType.ToString)
End If
'Dim blastring As String = dtVersion.Rows(0)("CurVersion").ToString
Debug.WriteLine("Done debuging")
cnADONetConnection.Close()
End Sub
================end of code