Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2003, 11:33 AM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default RowState Problem

The rowstate in my dataTable(without dataset) does not change (or gets changed back to 'unchange') when I want to add/delete back to the datasource. Its wierd because I am allowed to update rows. Basically, I can update the datasource but not add or delete. I don't get any errors and I'm connecting to an Access DB. Thank you for any help. Here is some code.

   sub filldgPubAuthors(pubID as integer)
             'retrives data and fills datatable
             Dim objConnection as new OledbConnection(ConfigurationSettings.AppSettings( "StrConnection"))
             dim objCmd As New OleDbCommand()
             Dim objParam As OleDbParameter
             With objCmd

                  .Connection = objConnection
                  .CommandText = "[qryPubAuthorWeb]"
                  .CommandType = CommandType.StoredProcedure
                  objParam = .Parameters.Add("PublicationID", OleDbType.integer)
             End With

             objParam.Direction = ParameterDirection.Input
             objParam.Value = pubID

             Try

               myAdapter = New OledbDataAdapter(objCmd)

                    addPrimaryKey()
               myAdapter.Fill(dtPubTable)
               viewState("pubTable") = dtPUbTable

                dgPubAuthors.dataSource = viewState("pubTable")
                dgPubAuthors.databind()

                'dgPubAuthors.Datasource = objDR
                'dgPubAuthors.DataBind()

             Catch objError As Exception

                labelError.Text = objError.Message

             Finally

                objConnection.Close()

             end try

         end sub
   sub AddDgINfo()
            'adds new row to the datatable
            dtPubTable = Ctype(viewState("pubTable"),Datatable)
             dim TempRow as Datarow
             tempRow = dtPubTable.NewRow()

             tempRow("dlOrder") = txtOrder.text
             tempRow("Name") = dlPersonID.selectedItem.text
             tempRow("PersonID") = dlPersonId.selectedItem.value
             tempRow("Pubrole") = dlRole.selectedItem.text
             tempRow("PubroleID") = dlRole.selectedItEm.value
             tempRow("Contribution") = txtContribution.text

             dtPubTable.Rows.Add(TempRow)
             response.write(temprow.RowState.ToString)
              temprow.RowState = DataRowState.Added
             viewState("pubTable") = dtPUbTable

         end sub


sub dgData_Delete(obj as object, e as DataGridCommandEventArgs)
             'this deletes a row in the datatable

             dim senderGrid as Datagrid = cType(obj, datagrid)

             generateDataTable()

             dim iId as string = Ctype(e.Item.FindControl("ID"), label).text
             dim dr as datarow = dtPubtable.Rows.Find(int32.parse(iId))

             dtPubTable.Rows.remove(dr)
             viewState("pubTable") = dtPUbTable
             dgPubAuthors.EditItemIndex = -1
             dataTableBind()

end sub

sub updateChild()
              'updates the datasource
              dtPubTable = cType(viewState("pubTable"),datatable)
              dtPubTable.Columns.remove("Name")
              dtPubTable.Columns.remove("PubRole")

              itable = dtPubTable.getChanges()

              dim strSQL as string = "SELECT tblPubAuthor.PubAuthorID, tblPubAuthor.PublicationID, tblPubAuthor.PubRoleID, tblPubAuthor.PersonID, tblPubAuthor.dlOrder, tblPubAuthor.Contribution " & _
                                             "FROM tblPubAuthor " & _
                                             "WHERE (((tblPubAuthor.PublicationID)=" & ViewState("hidPubID") & "));"

             dim objCommand as new oledbCommand(strSQL,objConnection)


            myAdapter.selectCommand = objCommand

            Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(myAdapter)

            myAdapter.Update(dtPubTable)

             dtPubTable.AcceptChanges()

         end sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
working with RowState in DataTable melvik C# 1 February 1st, 2007 08:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.