Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-08
28
Medium Priority
?
1,124 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:BangorCC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 10
  • +3
28 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 10784362
Some code would be helpfull
0
 

Author Comment

by:BangorCC
ID: 10784408
what are you looking for?

                Manager.EndCurrentEdit()
                Manager.AddNew()

                If Manager.Position <> Manager.Count - 1 Then
                    Manager.Position = Manager.Count - 1
                End If
0
 

Author Comment

by:BangorCC
ID: 10784418
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 96

Expert Comment

by:Bob Learned
ID: 10784430
Are you using a data adapter?

Bob
0
 

Author Comment

by:BangorCC
ID: 10784464
yes
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10784546
OleDbDataAdapter1.Update(DataSet)
0
 

Author Comment

by:BangorCC
ID: 10784943
what does dataadapter.update have to do with this?
0
 

Author Comment

by:BangorCC
ID: 10785436
This is the same problem that i have but there is no answer here

http://www.dotnet247.com/247reference/msgs/23/116043.aspx
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10785533
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
 

Author Comment

by:BangorCC
ID: 10785716
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10785730
What control is bound to the data source?

Bob

0
 

Author Comment

by:BangorCC
ID: 10785781
the controls on the form are bound textboxes and a couple of checkboxes they all display the data though.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10785797
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
 

Author Comment

by:BangorCC
ID: 10785941
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10785992
What is the code that you are using to add new?

Bob
0
 

Author Comment

by:BangorCC
ID: 10786002
               Dim editRow As DataRow = ds.Tables(CmdName).NewRow()
                ds.Tables(CmdName).Rows.Add(editRow)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10786064
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
 

Author Comment

by:BangorCC
ID: 10786353
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10786709
Actually when you add the new record what is the value of the CurrencyManager.Position property?

Bob
0
 

Author Comment

by:BangorCC
ID: 10786742
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10786763
You can try CurrencyManager.Refresh.

Bob
0
 

Author Comment

by:BangorCC
ID: 10786782
so the current position never advances when i add a new record
0
 

Author Comment

by:BangorCC
ID: 10786790
tried it plenty with no luck
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 10786839
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
 

Author Comment

by:BangorCC
ID: 10786928
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
 
LVL 3

Expert Comment

by:natejacobs
ID: 11051976
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
 

Expert Comment

by:scotthagie
ID: 12581136
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question