Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2004

Tip: Looking for answers? Try searching our database.

Problem with dataset updation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ratna veta - 13 Oct 2004 20:32 GMT
Hello,

I am having a problem with dataset. I am using vb.net,
oracle, ado.net. I am having a dataset(ds1) from which i
loop through and add it to another dataset(ds2). Calling
ds2.acceptchanges in the load of the form. And all the
data gets displayed in the grid. The user can modify any
row and can add new rows. On click of save I am just
calling ds2.haschanges and using ds2.getchanges and
merging with the original dataset (ds1). Now the problem
is once i click on save it saves perfectly but after that
if i make any changes add new rows or modify and click on
save again it does not do anything. The ds2.haschanges
returns nothing. Can anybody help me on this. I have tried
several things but it is not working. And one more thing i
noticed when i am not calling ds2.acceptchanges and saving
it multiples the data in the dataset like if i already
have 2 rows and added a new row it save total 6 rows. and
so on and so forth... I am new to .net can anybody help
plssss..

Thanks in advance
Sijin Joseph - 14 Oct 2004 05:20 GMT
After a successful save make sure that you call ds2.AcceptChanges()

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Hello,
>
[quoted text clipped - 18 lines]
>
> Thanks in advance
ratna veta - 14 Oct 2004 15:08 GMT
Sorry that is not working any other help pls..
ratna - 15 Oct 2004 19:35 GMT
Thank you for the suggestion but it is not working any
another workaround pls.
>-----Original Message-----
>After a successful save make sure that you call ds2.AcceptChanges()
[quoted text clipped - 27 lines]
>>
>> ***  
***

>.
Sijin Joseph - 18 Oct 2004 04:57 GMT
Hi Ratna,

could you post some code?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Thank you for the suggestion but it is not working any
> another workaround pls.
[quoted text clipped - 66 lines]
>
>>.
ratna veta - 18 Oct 2004 15:12 GMT
Hi Sijin,

Here is some code where in I load data into the gird getting the data
from another dataset which I have in a called EXTC.

   Private Sub LoadData()
       Dim oextc As EXTC = New EXTC
       grddata.DataBindings.Clear()
       m_oDS = oextc.GetData()
       ds.Tables.Clear()
       Dim t As New DataTable("testoracle")
       ds.Tables.Add(t)
       t.Columns.Add("extc_RecId", Type.GetType("System.Int64"))
       t.Columns.Add("extc", Type.GetType("System.String"))
       t.Columns.Add("Description", Type.GetType("System.String"))
       t.Columns.Add("INACTIVATE", Type.GetType("System.Boolean"))
       t.Columns.Add("CREATED_BY", Type.GetType("System.String"))
       t.Columns.Add("CREATED_DATE", Type.GetType("System.DateTime"))
       With m_oDS.Tables(0)
           Dim i As Integer
           For i = 0 To .Rows.Count - 1
               Dim r As DataRow = t.NewRow
               r(0) = .Rows(i).Item("extc_RECID")
               r(1) = .Rows(i).Item("extc")
               r(2) = .Rows(i).Item("Description")
               r(3) = .Rows(i).Item("INACTIVATE")
               r(4) = .Rows(i).Item("CREATED_BY")
               r(5) = .Rows(i).Item("CREATED_DATE")
               't.Rows.Add(r)
               t.Rows.Add(r)
           Next
       End With
       ds.Tables(0).Columns("extc_recid").ColumnMapping =
MappingType.Hidden
       ds.Tables(0).Columns("created_by").ColumnMapping =
MappingType.Hidden
       ds.Tables(0).Columns("created_date").ColumnMapping =
MappingType.Hidden
       '        AddCustomDataTableStyle()
       grddata.AllowSorting = True
       grddata.DataSource = ds
       grddata.DataMember = "testoracle"

       ds.AcceptChanges()
       'bindingManager = Me.BindingContext(grddata.DataSource,
grddata.DataMember)
       oextc = Nothing

   End Sub

On click of save I have the following code

Private Sub GetChangedRows()
       If ds.HasChanges Then
           Dim ChangedRecords As DataSet
           ChangedRecords = m_oDS.Clone
           ChangedRecords = ds.GetChanges(DataRowState.Modified)
           If Not ChangedRecords Is Nothing Then
               With ChangedRecords.Tables(0)
                   Dim s1 As EXTC = New EXTC
                   Dim b1 As Boolean
                   Dim i As Integer
                   For i = 0 To .Rows.Count - 1
                       b1 = s1.Updateextc(.Rows(i).Item("extc_RECID"),
.Rows(i).Item("extc"), .Rows(i).Item("description"),
CStr(.Rows(i).Item("INACTIVATE")))
                   Next
               End With
           End If
           ChangedRecords = ds.GetChanges(DataRowState.Added)
           If Not ChangedRecords Is Nothing Then
               Dim ds1 As New DataSet("test")
               ds1 = m_oDS.Clone
               With ChangedRecords.Tables(0)
                   Dim i As Integer
                   For i = 0 To .Rows.Count - 1
                       Dim r As DataRow = ds1.Tables(0).NewRow
                       r(0) = .Rows(i).Item("extc_recid")
                       r(1) = .Rows(i).Item("extc")
                       r(2) = .Rows(i).Item("description")
                       r(3) = .Rows(i).Item("inactivate")
                       r(4) = strUserName
                       r(5) = Now
                       ds1.Tables(0).Rows.Add(r)

                   Next
               End With

               If Not ds1 Is Nothing Then
                   m_oDS.Merge(ds1, True,
MissingSchemaAction.AddWithKey)

               End If
           End If

       End If
       SaveData() the code for this is below

       grddata.Refresh()
       'LoadData()
       ds.AcceptChanges()
   End Sub

Private Sub SaveData()
       Dim lRetVal As Long
       Dim oCustomer As EXTC = New EXTC
       Dim oDS_Delta As DataSet
       Dim sMsg As String

       If m_oDS Is Nothing Then Exit Sub
       '//? Check for changes with the HasChanges method first.
       If Not m_oDS.HasChanges() Then Exit Sub

       '//? Grab all changed rows
       oDS_Delta = m_oDS.GetChanges()
       sMsg = "Are you sure you want to save these " & _
              oDS_Delta.Tables(0).Rows.Count() & _
              " rows to the database?"
       lRetVal = MsgBox(sMsg,
Microsoft.VisualBasic.MsgBoxStyle.Question _
                 + Microsoft.VisualBasic.MsgBoxStyle.YesNo, _
                 "Save Records")
       Select Case lRetVal
           Case vbYes
               Try
                   '//? Save all changes
                   sMsg = oCustomer.SaveData(oDS_Delta)
                   ' LoadData()
               Catch e As Exception
                   sMsg = "Error saving data." & vbCrLf & vbCrLf & _
                          e.Message.ToString()
               Finally
                   MsgBox(sMsg, _
                       Microsoft.VisualBasic.MsgBoxStyle.Information, _
                       "Save Records")
               End Try
           Case vbNo
               '//? Do nothing
       End Select
       oDS_Delta = Nothing
       oCustomer = Nothing
   End Sub

this is for saving the main dataset m_ods.

Everything i change before i click save button first like modify add
rows work fine but clickingon the save and after that if i do any
changes and click on save ds.haschanges returns false..

Hope this is clear. Still need whole code I can post. Suggest me if my
code is bad or anything. Awaiting your help as it is very important for
me. thank you very much.

Ratna
Sijin Joseph - 19 Oct 2004 04:54 GMT
Hmm...Code seems OK, a couple of suggestions,

try calling AcceptChanges before refreshing the data in the datagrid,
also write an event handler for DataTable.RowChanging event in the
dataset ds. If the event is getting fired then the HasChanges should
return true.

Can you tell me after saving for the first time have you tried adding
multiple rows and then saving. There is a issue with the datagrid that
if you add one row and don't move to another row then the changes don't
get commited unless you call EndCurrentEdit() on the Binding.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Hi Sijin,
>
[quoted text clipped - 150 lines]
>
> Ratna
ratna veta - 20 Oct 2004 20:52 GMT
Hi Sijin,

Thank you for the suggestion but neither of the solutions worked. I
tried setting ds to nothing and then called loaddata again... it worked
:)))).

Thank you very much for your help.

Ratna

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.