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