running32
asked on
Updating Datagrid
I have a datagird in my windows form. l'm having problems updating the dataset and writing back to the database. On a mousedown event I want to add the username and date. This works. I then need to write in some comments then update the datagrid. My problem is that it will not update.
pt = New Point(e.X, e.Y)
Dim testdate As String
Dim hti As DataGrid.HitTestInfo = DataGrid2.HitTest(pt)
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid2.CurrentCell = New DataGridCell(hti.Row, hti.Column)
DataGrid2.Select(hti.Row)
DataGrid2.Item(hti.Row, 2) = UserName 'Column 3
DataGrid2.Item(hti.Row, 1) = Now 'Column 3
End If
pt = New Point(e.X, e.Y)
Dim testdate As String
Dim hti As DataGrid.HitTestInfo = DataGrid2.HitTest(pt)
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid2.CurrentCell = New DataGridCell(hti.Row, hti.Column)
DataGrid2.Select(hti.Row)
DataGrid2.Item(hti.Row, 2) = UserName 'Column 3
DataGrid2.Item(hti.Row, 1) = Now 'Column 3
End If
ASKER
on form leave I was was running the command
SqlDataAdapter4.Update(Dsh hnotes1)
Dshhnotes1.AcceptChanges()
SqlDataAdapter4.Update(Dsh
Dshhnotes1.AcceptChanges()
ASKER
If Dshhnotes1.HasChanges Then
SqlDataAdapter4.Update(Dsh hnotes1.Ta bles("tblH ouseholdno te"))
Dshhnotes1.AcceptChanges()
End If
When I add this to the on leave it does not reconize a change. how can I get it to see I have added to the datagrid.
Thanks
SqlDataAdapter4.Update(Dsh
Dshhnotes1.AcceptChanges()
End If
When I add this to the on leave it does not reconize a change. how can I get it to see I have added to the datagrid.
Thanks
ASKER
It will let me update any existing records but will not let me add any new records to the dataset.
1) Are you getting any exceptions?
2) Do you have an InsertCommand defined for the SqlDataAdapter?
Bob
2) Do you have an InsertCommand defined for the SqlDataAdapter?
Bob
ASKER
I am using a vs2003 sqldataAdapter. I checked the updates, insert commands and they are all ok.
No I am not getting any exceptions unfortunately just does not update. :-(
Thanks
No I am not getting any exceptions unfortunately just does not update. :-(
Thanks
Check to see if you have changes:
Dim changes AS DataSet = Dshhnotes1.GetChanges()
If Not changes Is Nothing Then
Console.WriteLine("Tables: " & changes.Tables.Count)
For Each table As DataTable in changes
Console.WriteLine(table.Ro ws.Count)
Next table
End If
Bob
Dim changes AS DataSet = Dshhnotes1.GetChanges()
If Not changes Is Nothing Then
Console.WriteLine("Tables:
For Each table As DataTable in changes
Console.WriteLine(table.Ro
Next table
End If
Bob
ASKER
When I try and add this to my code I get the error on "in changes" it states it is not a collection type.
Thank you
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is the code I am trying to work with. The records will update ok but I cannot add any new ones.
Thanks for your help. When I test to see if there is a change it always comes back as I for row count even if I have 4 rows. Thanks
**************Here is where I assign the datasource and formate the datagrid.
Dshhnotes1.Clear()
SqlDataAdapter4.SelectComm and.Parame ters("@par amhh").Val ue = lnghouseid
SqlDataAdapter4.Fill(Dshhn otes1)
DataGrid2.DataSource = Dshhnotes1
DataGrid2.DataMember = "tblhouseholdnote"
Me.DataGrid2.SetDataBindin g(Dshhnote s1, "tblHouseholdnote")
Dim tablestyle1 As New DataGridTableStyle
tablestyle1.MappingName = Dshhnotes1.Tables(0).Table Name
'Dim Data1a As New DataGridTextBoxColumn
Dim MemoTextCol As New DataGridMemoColumn
MemoTextCol.MappingName = "memeligibility"
MemoTextCol.HeaderText = "Memo"
MemoTextCol.NullText = ""
MemoTextCol.Width = 255
tablestyle1.GridColumnStyl es.Add(Mem oTextCol)
Dim Data2a As New DataGridTextBoxColumn
Data2a.MappingName = "dtmcreate"
Data2a.HeaderText = "Created"
Data2a.Width = 75
tablestyle1.GridColumnStyl es.Add(Dat a2a)
Dim Data3a As New DataGridTextBoxColumn
Data3a.HeaderText = "Created By"
Data3a.MappingName = "strcreate"
Data3a.Width = 95
tablestyle1.GridColumnStyl es.Add(Dat a3a)
Dim Data4a As New DataGridTextBoxColumn
Data4a.HeaderText = "Created By"
Data4a.MappingName = "lnghouseid"
Data4a.Width = 20
tablestyle1.GridColumnStyl es.Add(Dat a4a)
Me.DataGrid2.TableStyles.A dd(tablest yle1)
********** Here is where I assign some values to the datagrid
Private Sub DataGrid2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles DataGrid2.MouseUp
pt = New Point(e.X, e.Y)
Dim testdate As String
Dim hti As DataGrid.HitTestInfo = DataGrid2.HitTest(pt)
If IsDBNull(DataGrid2.Item(ht i.Row, 0)) = True Then
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid2.CurrentCell = New DataGridCell(hti.Row, hti.Column)
DataGrid2.Select(hti.Row)
DataGrid2.Item(hti.Row, 1) = Now 'Column 2
DataGrid2.Item(hti.Row, 2) = UserName 'Column 3
DataGrid2.Item(hti.Row, 3) = lnghouseid 'Column 4
End If
End If
*********************** On Datagrid on leave I update the dataset
Me.BindingContext(Dshhnote s1.Tables( 0)).EndCur rentEdit()
SqlDataAdapter4.Update(Dsh hnotes1.Ta bles(0))
Dshhnotes1.AcceptChanges()
Thanks for your help. When I test to see if there is a change it always comes back as I for row count even if I have 4 rows. Thanks
**************Here is where I assign the datasource and formate the datagrid.
Dshhnotes1.Clear()
SqlDataAdapter4.SelectComm
SqlDataAdapter4.Fill(Dshhn
DataGrid2.DataSource = Dshhnotes1
DataGrid2.DataMember = "tblhouseholdnote"
Me.DataGrid2.SetDataBindin
Dim tablestyle1 As New DataGridTableStyle
tablestyle1.MappingName = Dshhnotes1.Tables(0).Table
'Dim Data1a As New DataGridTextBoxColumn
Dim MemoTextCol As New DataGridMemoColumn
MemoTextCol.MappingName = "memeligibility"
MemoTextCol.HeaderText = "Memo"
MemoTextCol.NullText = ""
MemoTextCol.Width = 255
tablestyle1.GridColumnStyl
Dim Data2a As New DataGridTextBoxColumn
Data2a.MappingName = "dtmcreate"
Data2a.HeaderText = "Created"
Data2a.Width = 75
tablestyle1.GridColumnStyl
Dim Data3a As New DataGridTextBoxColumn
Data3a.HeaderText = "Created By"
Data3a.MappingName = "strcreate"
Data3a.Width = 95
tablestyle1.GridColumnStyl
Dim Data4a As New DataGridTextBoxColumn
Data4a.HeaderText = "Created By"
Data4a.MappingName = "lnghouseid"
Data4a.Width = 20
tablestyle1.GridColumnStyl
Me.DataGrid2.TableStyles.A
********** Here is where I assign some values to the datagrid
Private Sub DataGrid2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
pt = New Point(e.X, e.Y)
Dim testdate As String
Dim hti As DataGrid.HitTestInfo = DataGrid2.HitTest(pt)
If IsDBNull(DataGrid2.Item(ht
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid2.CurrentCell = New DataGridCell(hti.Row, hti.Column)
DataGrid2.Select(hti.Row)
DataGrid2.Item(hti.Row, 1) = Now 'Column 2
DataGrid2.Item(hti.Row, 2) = UserName 'Column 3
DataGrid2.Item(hti.Row, 3) = lnghouseid 'Column 4
End If
End If
*********************** On Datagrid on leave I update the dataset
Me.BindingContext(Dshhnote
SqlDataAdapter4.Update(Dsh
Dshhnotes1.AcceptChanges()
Bob