Help with using DataView to insert Record..Please!

Tech-Archive recommends: Fix windows errors by optimizing your registry



I'm new to ado.net/asp.net and have been on a crash course these last
few days. I've been stuck on this current problem for over a day and it
seems pretty simple, but I can't get it to work. I'd like to create a
data view from a data table, insert a record into that data view and
have it inserted back into the actual database (Access 2000). Following
tutorials online, I've been able to use a dataadapter to connect to the
database, then using a datatable, insert new rows and have them
inserted in the actual database. But when it comes to doing that same
functionality via a dataview, I've had no luck. Here is the code I've
been using. It generates no errors, and a new row is added to the
underlying datatable, but nothing is ever sent back to the database. I
think it might have something to do with the myAdpater.InsertCommand
code (are these used the same way in DataViews as in DataTables?).
Thanks in advance for any advice.

Public Sub editLevelProgressFromView()

'Objects used to connect/read from database
Dim cs As ConnectionStringSettings
Dim myConnection As OleDbConnection
Dim myAdapter As OleDbDataAdapter
Dim myTable As DataTable
Dim myView As DataView
Dim myRow As DataRowView

Dim sqlStr As String

cs = ConfigurationManager.ConnectionStrings("strConn")
myConnection = New OleDbConnection(cs.ConnectionString)


sqlStr = "Select * from tblTest"
myAdapter = New OleDbDataAdapter(sqlStr, myConnection)

'Set up insert commands for use on myAdapter.Update method
myAdapter.InsertCommand = New OleDbCommand("INSERT INTO tblTest
(c_name, c_number) VALUES(?, ?)", myConnection)
myAdapter.InsertCommand.Parameters.Add("@c_name",
OleDbType.VarChar, 15, "c_name")
myAdapter.InsertCommand.Parameters.Add("@c_number",
OleDbType.VarChar, 30, "c_number")

'Fill Table and create View
myTable = New DataTable()
myAdapter.Fill(myTable)
myView = myTable.DefaultView

'Add Row to myView, insert data via BeginEdit and EndEdit methods
myRow = myView.AddNew()
myRow.BeginEdit()
myRow("c_name") = "testName"
myRow("c_number") = "testNumber"
myRow.EndEdit()

'Accept changes in table from view
myTable.AcceptChanges()

'Commint changes to database (does not work, but no error thrown)
myAdapter.Update(myTable)

End Sub

.



Relevant Pages

  • Re: Removing rows from a DataTable is VERY slow
    ... but now I feel that I can keep my design and the ... >> my DataTables, a little better explanation of my design thoughts and ... >> So my design idea was that when reading rows from a database table I ... >> corresponding business object for each returned row, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Adding rows to DataGrid across multiple PostBacks
    ... (not adding to the database or whatever you want to perform ... is only after adding information for every Id Number to the datagrid.) ... datasource which can contain a collection of datatables. ... The user can then put in a new IDNumber, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Compare DataTable Row vs Database Row?
    ... Welcome to Microsoft Newsgroup Support service. ... The best method to compare a data row in database with an ADO.NET DataTable ... DataTables. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Strategy / direction?
    ... > with records in the other 3rd-party database. ... DataTables can be bound to each other through DataRelations - these can be ... matches the command object for the respective command. ... it will loop through the datatable and for every row with a rowstate ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Strategy / direction?
    ... > with records in the other 3rd-party database. ... DataTables can be bound to each other through DataRelations - these can be ... matches the command object for the respective command. ... it will loop through the datatable and for every row with a rowstate ...
    (microsoft.public.dotnet.general)