Search the Community
Showing results for tags 'dataset'.
-
In my sample XML the object is "ZB". That "ZB" has two points, "AAD" and "AAG". Both points have coördinates, devided by the "|" character. This is a fixed format, I have to deal with it. Because in our software, we use the data in a dataset. So we convert the XML tot a dataset with the command: Dim myDS As DataSet Dim fsReadXml As New System.IO.FileStream(myXMLFile, System.IO.FileMode.Open) myDS.ReadXml(fsReadXml) After that, I have 4 tables in my dataset: ZB AAE AAG point Automaticly there are relations and hidden id's added. After that, I connect 2 datagrids with this code. One datagrid with all objects and the second grid shows me the coördinates of the selected object in datagrid 1: Dim myBS As New BindingSource myBS.DataSource = myDS DataGridView1.DataSource = myBS DataGridView1.DataMember = "ZB" DataGridView2.DataSource = myBS DataGridView2.DataMember = "ZB.ZB_AAE.AAE_point" So far so good, everything works fine! I can databind labels or other textboxes to the point, after clicking a "ZB" object. Its with this code: TextBox1.DataBindings.Clear() TextBox1.DataBindings.Add(New Binding("text", myBS, "ZB.ZB_AAG.AAG_point.pos")) What do I want? I want the objects and coördinates in one datagrid. So I want to create a view, adding a custom column, and see the results back in a datagrid. I tried the following. All commented lines I tried. I can't find the proper way to build a expression so the coördinates were shown: Dim Test As DataColumn = myDS.Tables("ZB").Columns.Add("test", GetType(String)) Test.Expression = "ZB.ZB_AAE.AAE_point" 'Test.Expression = "Child(ZB.ZB_AAE).point" 'Test.Expression = "Child(ZB_AAE).point" 'Test.Expression = "Child(point)" 'Test.Expression = "Child(pos)" 'Test.Expression = "ZB_AAE.point" 'Test.Expression = "ZB.ZB_AAE.point.pos" 'Test.Expression = "point" 'Test.Expression = "point.pos" 'Test.Expression = "Parent.ZB_AAE.AAE_point.pos" 'Test.Expression = "Parent(ZB_AAE).AAE_point" 'Test.Expression = "Parent.ZB" 'Test.Expression = "ZB_AAE.AAE_point.pos" 'Test.Expression = "Child.ZB_AAE.point.pos" You can use this XML to test: <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <!-- File Header --> <DATA xmlns:nl= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:EN13508.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml"> <ZB> <AAA>AAA</AAA> <AAD>1</AAD> <AAE> <gml:point srsName="Netherlands-RD" srsDimension="2"> <gml:pos>123|456</gml:pos> </gml:point> </AAE> <AAF>2</AAF> <AAG> <gml:point srsName="Netherlands-RD" srsDimension="2"> <gml:pos>234|567</gml:pos> </gml:point> </AAG> </ZB> <ZB> <AAA>AAA</AAA> <AAD>3</AAD> <AAE> <gml:point srsName="Netherlands-RD" srsDimension="2"> <gml:pos>345|678</gml:pos> </gml:point> </AAE> <AAF>4</AAF> <AAG> <gml:point srsName="Netherlands-RD" srsDimension="2"> <gml:pos>456|789</gml:pos> </gml:point> </AAG> </ZB> </DATA>
-
- databinding
- datagrid
-
(and 3 more)
Tagged with:
-
A am trying to make a simple database application just to learn SQLCE. I can not get the simplest things to work: adding and deleting records. Here´s how it looks now: Conn = New SqlCeConnection(CS) 'set the connection Conn.Open() 'and open it 'the database has 1 table called Invoices and 2 columns. First column called ID (identity with auto increment set to true) is the primary key. Second is a string (nvarchar) column called InvoiceNo. TA = New SqlCeDataAdapter("SELECT * FROM Invoices", Conn) 'set the data adapter CB = New SqlCeCommandBuilder(TA) Dim DSF as New Dataset 'a blank dataset TA.Fill(DSF, "Invoices") 'filling the dataset DSF.Tables("Invoices").PrimaryKey = New DataColumn() {DSF.Tables("Invoices").Columns("ID")} 'I need a primary key to easily search for records in dataset by ID 'there is a DataGridView called DG on the form DG.DataSource = DSF DGFaktury.DataMember = "Invoices" Works nicely. Loads all data into the datagrid. Now I want to insert a record: Dim R As DataRow = DSF.Tables("Invoices").NewRow R.Item("InvoiceNo") = "027" DSF.Tables("Invoices").Rows.Add(R) TA.Update(DSF, "Invoices") 'so far so good I can get the new row into the database. But in my datagrid I see only the new InvoiceNo, but not the new ID. Of course the dataset doesn´t know what ID was assigned to the new row in the database, so I have to get it somehow. So here´s what I did. Dim cmd As New SqlCeCommand("SELECT ID FROM Invoices WHERE (ID = @@IDENTITY)", Conn) Dim id As Integer = CInt(cmd.ExecuteScalar()) R.Item("ID") = id 'now I see the ID of newly added record - wow Here comes the problem: there is a Delete button on my form. When I click it, and the newly added row in the datagrid is selected, it executes this: Dim ID As Integer = DG.SelectedRows(0).Cells("ID").Value 'retrieves the ID DSF.Tables("Invoices").Rows.Find(ID).Delete() 'finds a row in the dataset and deletes it TA.Update(DSF, "Invoices") I ended up with an exception: DBConcurrencyException, DeleteCommand affected 0 of 1 expected rows. After inserting the new row, the dataset changed when I changed the ID, so it thinks it has to update the record while deleting it at the same time and that´s what is causing the error. Is that right? There´s no problem while deleting older records. Am I going the right direction? Is there another way to get these simple operations (insert, delete, update) to work? I found tutorials dealing with wieving of data only, but not inserting, updating or deleting.
- 1 reply
-
- dataadapter
- datagridview
-
(and 3 more)
Tagged with: