|
-
May 23rd, 2013, 09:05 AM
#1
Thread Starter
Addicted Member
Comparing data on a DataGridView and an XML file
Hi again everyone.
I've come this time with a different problem for me to solve...
My company has an xml file which has most of the customer's information stored, the company is on a phase of automating daily routines and one of them is to check for any problems with current purchasing orders, deliveries and so on...
So I was asked to get an application to automate this routine, in order to save hours of expendable work.
Anyway, here's what I need to know:
I have an xml file as I've already stated before and the application has a DGV, the whole code is working great, data is being shown on the DGV (which is not what's intended) and now I need to know how I compare the data on xml file with the data of a specific table that is stored on a variable (I've stored this data with a Stored Procedure).
Here's the code to better explain myself:
Code:
Public Function _devolverDadosXML_viaSP(ByVal NomeSP As String) As DataTable
Dim FieldValues(0) As Object 'A Temporary Variable to retrieve all columns in a row and fill them in Object array
_minhaLigacaoSQL.ConnectionString = _connectionString
_minhaLigacaoSQL.Open()
_instrucaoSQL.CommandText = NomeSP
_instrucaoSQL.CommandType = CommandType.StoredProcedure
_instrucaoSQL.Connection = _minhaLigacaoSQL
'_instrucaoSQL.Parameters.Add(New SqlClient.SqlParameter("codigolocalentrega", SqlDbType.VarChar, 50, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Current, "Y%"))
_SQLDBDataReader = _instrucaoSQL.ExecuteReader()
_umaTabela.Columns.Add("codigolocalentrega", GetType(String))
While (_SQLDBDataReader.Read)
_SQLDBDataReader.GetValues(FieldValues)
_umaTabela.Rows.Add(FieldValues)
End While
For i As Integer = 0 To _umaTabela.Rows.Count - 1
Next
Return Nothing 'Ignore this line of code as I wrote it only to get past the function general error...
Note: As you probably noticed, this function is suposed to return a datatable, though I'm not quite sure what the fuction is really supose to return at this stage, but it's not relevant to the question I'm having at this point.
According to this code you can see that the connection is made and data is stored on a Stored Procedure, which in turn stores the data that it reads into a variable named FieldValues, where this value is added into a table (inside a loop), finally I'm navigating through every row of the table, getting myself ready to compare each row to the "node" on the xml file.
I need to know how I compare each row to each node on the xml file and then bring the nodes that are associated to that node, into the DGV
-
May 23rd, 2013, 09:49 AM
#2
Re: Comparing data on a DataGridView and an XML file
You don't need any loops to read the data. Either call the Load method of your DataTable to populate it with the entire result set from the data reader or else use a data adapter and call Fill. You can follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data for examples of both.
The next step is to read the XML data. From the sound of it, you should probably use an XmlTextReader to read one record at a time, which you can then compare to all the records in the DataTable. You should read about the XmlTextReader at MSDN and search the web for examples if you need them. You can then post back with specific questions when you find issues that you cannot resolve.
You may also want to do some reading on the various other ways to read XML data to be sure that you're using the best option under the circumstances. I'm no expert when it comes to XML handling but, from what I do know, it seems that an XmlTextReader is the best option.
-
May 23rd, 2013, 10:21 AM
#3
Thread Starter
Addicted Member
Re: Comparing data on a DataGridView and an XML file
 Originally Posted by jmcilhinney
You don't need any loops to read the data. Either call the Load method of your DataTable to populate it with the entire result set from the data reader or else use a data adapter and call Fill. You can follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data for examples of both.
The next step is to read the XML data. From the sound of it, you should probably use an XmlTextReader to read one record at a time, which you can then compare to all the records in the DataTable. You should read about the XmlTextReader at MSDN and search the web for examples if you need them. You can then post back with specific questions when you find issues that you cannot resolve.
You may also want to do some reading on the various other ways to read XML data to be sure that you're using the best option under the circumstances. I'm no expert when it comes to XML handling but, from what I do know, it seems that an XmlTextReader is the best option.
Thank you for the help and suggestions, but those were the ones I already check and tried on the application, they're not sufficient for this specific case, because my IT co-workers kinda of "messed up" when creating the DB for the company, I quoted messed up, because they were, in a certain way, forced to create tables that would relate to others and that would only have key codes that refer to data (alpha-numerical) on xml files and thus we can't access the data we need to manipulate, directly on DGVs... leaving me with this annoying problem lol...
Well it's allright now, because my colleagues and I did a bit of brainstorming about this matter and they remember that there were a few algorythms already implemented that do the similar process of what I need for my case.
In my case I have to create a Stored Procedure that finds the correct position of each node on the xml file, then I need to use another Stored Procedure, which I created, that gets the data from "key nodes" (these nodes are like columns of a table ^^ took me a while to understand this part lol) of the xml file, then I need to check if the "key nodes" match the correct data for each "key node" and when they do retrive the data and show it up on the DGV in order to edit the data there...
I know this sounds confusing, but it's really the way this is suposed to be and trust me if you feel confused, imagine me when I found out the solution xD
Thanks for everything anyway.
-
May 23rd, 2013, 11:25 AM
#4
Re: Comparing data on a DataGridView and an XML file
but it's really the way this is suposed to be
Hmm. It may be the way it has to be. I doubt whether anyone would agree that it's the way it should be.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|