473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DataGrid / DataView Problems

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
Nov 21 '05 #1
8 1250
NetRacer,

This is in my opinion impossible to answer without code.
Can you show the code from this event.
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.


Cor
Nov 21 '05 #2
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" <no************@planet.nl> schrieb im Newsbeitrag
news:Od**************@TK2MSFTNGP09.phx.gbl...
NetRacer,

This is in my opinion impossible to answer without code.
Can you show the code from this event.
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.


Cor

Nov 21 '05 #3
ahhh... stop, i found the error. a property set of a form property reloaded
the table from database. *grml*... stupid error
Nov 21 '05 #4
NetRacer,

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

Try
cbGrid = New MySqlCommandBuilder(daGrid)

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/de...chematopic.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

Nov 21 '05 #5
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" <no************@planet.nl> schrieb im Newsbeitrag
news:OL**************@tk2msftngp13.phx.gbl...
NetRacer,

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

Try
cbGrid = New MySqlCommandBuilder(daGrid)

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/de...chematopic.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

Nov 21 '05 #6
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
Nov 21 '05 #7
Ä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" <no************@planet.nl> schrieb im Newsbeitrag
news:OU*************@tk2msftngp13.phx.gbl...
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

Nov 21 '05 #8
Netracer

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

:-)

Cor
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
4
by: - R | last post by:
Hello all. I'm new to .Net so please help me out. I have a application with several "Threads" running to observe various things. From time to time each thread need to add an log entry, which...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
0
by: Frnak McKenney | last post by:
One of the reasons given for the Allied victory in WWI is that the Nazi armament industry invested so much effort in creating new weapons (e.g. the jet plane) it wasn't able to develop any of them...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
4
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to...
8
by: Dennis | last post by:
How do I sort a DataGrid Column in code without clicking on the column header? -- Dennis in Houston
9
by: John Hernry | last post by:
I have been watching the dotnet newsgroups for a couple of weeks now and scouring the net looking for a solution to my datagrid find functionality. With no luck. I am hoping that you can help me....
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.