currency manager .addnew adds a record to the dataset but it does not show

i'm using a currency manager with binding context on a form.  when i invoke the .addnew method the manager.count property increments itself however the new record is not visible on the form.  The addnew method is supposed to make the new record the current focus after it adds it.  The record isn't even visible when i move to the end of the recordset.  Also i have a movelast function that is supposed to goto count-1 and this does not work after i add the new record.  Whats going on here?
BangorCCAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
This is an example of how I add new records:

This is using a SQLDataAdapter and a strong typed dataset.  This is all done without a CurrencyManager, but the values are known before the record is added.

               ' Add a new row, and retrieve the values from the form.
               Dim newRow As dataReferences.HintsRow = _
                  dataReferences.Hints.NewHintsRow

               newRow.Title = .textTitle.Text
               newRow.Hints = .textHints.Text

               ' Add a new row to the table.
               Me.dataReferences.Hints.AddHintsRow(newRow)

               ' Update the database with the added record.
               Me.adapterHints.Update(Me.dataReferences.GetChanges(DataRowState.Added))

               ' Move to the new row.
               Me.gridHints.Row = Me.gridHints.Rows.Count - 1

I am sorry that it is taking me this long to help you with your problem.  I have a lot of specific experience with ADO.NET, and I use E-E as both a teaching and a learning tool for my certification.

Bob
0
 
RonaldBiemansCommented:
Some code would be helpfull
0
 
BangorCCAuthor Commented:
what are you looking for?

                Manager.EndCurrentEdit()
                Manager.AddNew()

                If Manager.Position <> Manager.Count - 1 Then
                    Manager.Position = Manager.Count - 1
                End If
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
BangorCCAuthor Commented:
this is where the problem is after i call add new the dataset table adds a record then the manager cannot move to that record
0
 
Bob LearnedCommented:
Are you using a data adapter?

Bob
0
 
BangorCCAuthor Commented:
yes
0
 
Bob LearnedCommented:
OleDbDataAdapter1.Update(DataSet)
0
 
BangorCCAuthor Commented:
what does dataadapter.update have to do with this?
0
 
BangorCCAuthor Commented:
This is the same problem that i have but there is no answer here

http://www.dotnet247.com/247reference/msgs/23/116043.aspx
0
 
Bob LearnedCommented:
Data access in ADO.NET is in a disconnected fashion.  When you make changes to the data source, it doesn't make any changes to the table until you update the database using the Update method from the data adapter.

Bob
0
 
BangorCCAuthor Commented:
yes, however i am trying to add a record to the disconnected information which my form is bound to so i can edit it and then update it.  My problem is when i use the addnew method of the manager it seems to add a new record (the manager count increases) however i cannot view this record anywhere.  I have tried using the update function as well.
0
 
Bob LearnedCommented:
What control is bound to the data source?

Bob

0
 
BangorCCAuthor Commented:
the controls on the form are bound textboxes and a couple of checkboxes they all display the data though.
0
 
Bob LearnedCommented:
From the help file on CurrencyManager.AddNew:

You typically use this property only if you are creating your own control incorporating the CurrencyManager. Otherwise, to add items, if the data source is a DataView, use the AddNew method of the DataView class. If the data source is a DataTable, use the NewRow method and add the row to the DataRowCollection.

Bob
0
 
BangorCCAuthor Commented:
ok that seems to be getting me somewhere now.  I have another problem now... i create the new row then i add the row to the table and get an error because the row contains nulls in required fields... is there anyway i can add this row to the table and then edit its contents?  or is there a way to temporarily bind the controls to this new row and after that bind it back to the datatable?
0
 
Bob LearnedCommented:
What is the code that you are using to add new?

Bob
0
 
BangorCCAuthor Commented:
               Dim editRow As DataRow = ds.Tables(CmdName).NewRow()
                ds.Tables(CmdName).Rows.Add(editRow)
0
 
Bob LearnedCommented:
You are trying to add a blank row so that you can edit it, correct?  You will have to put some values into the required fields or you won't be able to do this.  Is there a reason for setting the Required property for the fields?  I tend to find that Required = False, along with AllowZeroLength = True, is the way I go, and then use validation within the code to force that.

Bob
0
 
BangorCCAuthor Commented:
so now i have the same problem i started with i can add a row and the manager count increments but i still cannot view the new record
0
 
Bob LearnedCommented:
Actually when you add the new record what is the value of the CurrencyManager.Position property?

Bob
0
 
BangorCCAuthor Commented:
its at 0 i have code to move it to the last if its not already but it runs right past that and i can only go as far as the last record before i added the record
i know that the row is being added though i went through the datatable printing a couple of fields for all of them
0
 
Bob LearnedCommented:
You can try CurrencyManager.Refresh.

Bob
0
 
BangorCCAuthor Commented:
so the current position never advances when i add a new record
0
 
BangorCCAuthor Commented:
tried it plenty with no luck
0
 
BangorCCAuthor Commented:
don't worry about it you have helped before and i'm sure that you will help again.  I believe that i need to know all the values before I can add this record to a field.  I'm giving you the points for trying so hard.  I am going to find a way to drop the current binding, then bind it to the row that i am creating and once done i am going to add the row and return to the old binding... so that is my plan of action.  Gotta love those days when you think about a problem all day and then compromise on a different solution at the end of it.
0
 
natejacobsCommented:
It looks to me that you're calling CurrencyManager.EndCurrentEdit()  BEFORE adding the new row.

EndCurrentEdit() is supposed to make your changes visible in the Dataset, but only if the row is already there.  
Currency Manager links:

http://support.microsoft.com/default.aspx?scid=kb;en-us;q313482
http://www.codeproject.com/vb/net/databindingconcepts.asp?df=100&forumid=14573&exp=0&select=420739
0
 
scotthagieCommented:
Addnew will error out and show the currentrecord as 0 in some cases, I found it related to the datetimepickers having null values by default, but I suspect other controls have the same problems with null values. One solution I have found is to set the default values when creating the dataset:

        MyDataSet.Tables("Proposal").Columns("DateEntered").DefaultValue = Today

Of course, I have whole new problems with addnew, but that solved that immediate one.
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.