Groups | Blog | Home
all groups > vb.net data > june 2005 >

vb.net data : DataGrid / DataView Problems


NetRacer
6/27/2005 12:00:00 AM
hi,

i have a DataGrid with a DataView as source. the data is read correctly from
the db and shown on screen.
the problem appears, when i want to add some rows to the grid.

first it adds them and the ListChangedEvent from the DataView raises and the
new values are shown correctly.
but if i then click on the save button (which calls the EndCurrentEdit and
Update methods), the DataView suddenly only has the original rows and the
new ones are lost.

then if i try again to add some values, they are lost imediately when i
leave the current row in the DataGrid.

there are no constraints, keys or other restrictions in the underlaying
DataTable.

a suggestion:
at first addition of the row there raises a strange second ListChangedEvent
after the ItemAdded. the ListChangedType is ItemMoved, then OldIndex equals
the current row and the NewIndex something like -23423435. is my problem
there?

thx for any help
netracer

Cor Ligthert
6/27/2005 8:11:17 PM
NetRacer,

This is in my opinion impossible to answer without code.
Can you show the code from this event.

[quoted text, click to view]

Cor

NetRacer
6/28/2005 12:00:00 AM
Ähhhm... sorry, but i could not really understand your joke (it was one,
wasn't it?). i'm not a naturally english speaker (as you can see in my bad
english, i think)...

by the way: YourSQL really exists. it's a frontend tool for MySQL ;)

however, thanx again for your try to help
netracer



"Cor Ligthert" <notmyfirstname@planet.nl> schrieb im Newsbeitrag
news:OURjtt8eFHA.892@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Cor Ligthert
6/28/2005 12:00:00 AM
Netracer

You can interpret it as a joke, it was just a stupid mistake from me reading
your code.

:-)

Cor

NetRacer
6/28/2005 8:16:35 AM
Private Function SaveDataGrids(ByVal grid As DataGrid, Optional ByVal
ShowErrors As Boolean = True) As Boolean

Dim cnt As Integer = 0
Dim dvGrid As DataView

dvGrid = CType(grid.DataSource, DataView)

Dim daGrid As New MySqlDataAdapter(String.Format("SELECT * FROM {0}
", dvGrid.Table.TableName), conn)
Dim cbGrid As MySqlCommandBuilder

Try
cbGrid = New MySqlCommandBuilder(daGrid)

'-----
'if i set a breakpoint here, the record is already lost
'-----
Me.BindingContext(grid.DataSource).EndCurrentEdit()

cnt = daGrid.Update(dvGrid.Table)

'MessageBox.Show(cnt.ToString & " lines from " &
dv.Table.TableName & " updated.", _
'"Datenbankinfo", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Catch ex As MySqlException
If cnt <= 1 And ShowErrors Then
MessageBox.Show(ex.Message, "Datenbankfehler",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try

Return (cnt > 0)
End Function




"Cor Ligthert" <notmyfirstname@planet.nl> schrieb im Newsbeitrag
news:Od2b9O0eFHA.1448@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

NetRacer
6/28/2005 9:12:38 AM
ahhh... stop, i found the error. a property set of a form property reloaded
the table from database. *grml*... stupid error

Cor Ligthert
6/28/2005 9:39:36 AM
NetRacer,

[quoted text, click to view]
You dataadapter has not any schemainformation, how would it create the
commands.

I never did it this way, however you can try the Dataadapter.fillschema in
advance, I assume that it will solve your problem.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatacommondbdataadapterclassfillschematopic.asp

There is written that it adds a datatable. Therefore I assume it is not
going 1:1

The datatable that uses your dvGrid is just dvGrid.DataTable

I hope this helps,

Cor


NetRacer
6/28/2005 10:15:47 AM
the schema is/was not the problem. the command is created correctly.
look the log of MySQL:

"UPDATE `tbl_ersatz_abs` SET `Rekl_ID`=1, `Pos`=4, `ErsatzAB`=1644437,
`ErsatzABText`='@Y', `ZNA_ID`=4 WHERE `E_AB_ID` <=> 5 AND `Rekl_ID` <=> 1
AND `Pos` <=> 4 AND `ErsatzAB` <=> 1644437 AND `ErsatzABText` <=> '@Z' AND
`ZNA_ID` <=> 4; SELECT `E_AB_ID`, `Rekl_ID`, `Pos`, `ErsatzAB`,
`ErsatzABText`, `ZNA_ID` FROM `tbl_ersatz_abs` WHERE (`E_AB_ID`=5)"


if you're not familiar with MySQL: the operator <=> does a 'NULL-safe equal'
comparison.

if i use FillSchema or the AddWithSchema option, the grid annoys me with
popup boxes that i should set an ID. i don't want to set an ID in my
program, i want the server to do this.

by the way the Fill is done much earlier at loading the form.



the problem was a few lines before the posted sub. another datasource was
saved there and at the EndCurrentEdit of this saving a property set was
called which did a new select on the database and so overwrote my changes.

however, thanx for trying to help
netracer



"Cor Ligthert" <notmyfirstname@planet.nl> schrieb im Newsbeitrag
news:OL4FpS7eFHA.2700@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Cor Ligthert
6/28/2005 12:22:34 PM
NetRacer,

I was misinterpretting your code of MySQL. I thought: "is it MySQL or
YourSQL?
However just a kind of blindness it very clear.

:-))

Sorry

Cor

AddThis Social Bookmark Button