• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

Datagridview Comparing / Crystal Report

Im on the last part of my little project, all items are generated and ready for the last step.

I have 2 datagridviews,

datagridview2, items are populated via a sql mdf file.
datagridview3, items are populated via mutiple txt files.

My goal is to do the following,

check items in datagridview2 vs datagridview3, and have the missing items put into another datagridview to be used on a crystal report. I don't have the proper skill for this so some serious help is very welcome with easy to follow code.

End result,

Click a button, compares datagridview2 & 3, output to new datagridview4, then writes datagridview4 to it's own datatable for use in a crystal report.

This is the last part for me and then some freedom and mind releaf haha. Thank you so much!
0
Jack_Jones
Asked:
Jack_Jones
  • 7
  • 7
1 Solution
 
CodeCruiserCommented:
You can use the same looping and filtering you used earlier to populate the grid4. Then use the following tutorial about feeding it to crystal

http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx

http://www.codeproject.com/KB/cs/CreatingCrystalReports.aspx
0
 
Jack_JonesAuthor Commented:
Project is due tomorrow and I have worked non stop on it, if you could help I would be very thankful. This is the last part to the finish line.
0
 
CodeCruiserCommented:
Have you started on this? What specific part you need help with? You work on saturdays?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Jack_JonesAuthor Commented:
Yeah I have to present this tomorrow, the part im stuck on is this.

Compare the datagridview2 & 3, export data difference using xml for the report viewer to sort.

datatable.dataset.writexml("File Location") <- Figured this would be easy once I can figure out how to write this to a dataset.

 Dim reportData As New DataTable
        reportData.Columns.Add("SKU", GetType(String))
        reportData.Columns.Add("Item Description", GetType(String))
        reportData.Columns.Add("QTY", GetType(String))
        reportData.Columns.Add("RTL Price", GetType(String))
        reportData.Columns.Add("Category", GetType(String))

        Try
            For lpz As Integer = 0 To 500
                Dim drow As DataRow = reportData.NewRow()
                drow(0) = skzInfo(lpz)
                reportData.Rows.Add(drow)
                drow(1) = InfoDes(lpz)
                drow(2) = InfoQty(lpz)
                drow(3) = InfoRTL(lpz)
                drow(4) = InfoMod(lpz)
            Next lpz
        Catch
        End Try

Open in new window



To compare, im at a total loss because that was for listview vs datagridview, and i was able to do all datagridviews and was very pleased with that result.
0
 
Jack_JonesAuthor Commented:
I was trying reportData.DataSet.WriteXML("File Location.xml") so that maby I could have VB Report read the xml file and sort it. Not sure don't want to make this to hard as my mind is already smoking out of my ears lol.
0
 
CodeCruiserCommented:
For gridviews, you can do something like

For i As Integer = 0 to DataGridView3.Rowcount - 1
     dTable4.DefaultView.RowFilter = "columnname=" & DataGridView3.Item(columnindex, i).Value
     if dTable4.DefaultView.Count = 0 Then
        'code to insert row as in http:#36970651
     End If
Next
0
 
Jack_JonesAuthor Commented:
Well can't seem to make that work, got a blue squigly line that I can resolve,

DatagridView3.Item(columnindex, i).value <- columnindex causes issue

---------------------------------

Have to figure something out it's crunch time for me =\
0
 
CodeCruiserCommented:
columnindex is to be replaced by an actual column index such as 0 or 1 etc depending on which column you want to compare for existing in the other grid.
0
 
Jack_JonesAuthor Commented:
DefaultView.RowFilter = "columnname="
Cannot find column [columnname].
0
 
CodeCruiserCommented:
Again, replace it with an actual columnname.
0
 
Jack_JonesAuthor Commented:
Wish you could see what I see lol, it's just doing something but giving an error with the first item in the column as the error lol.
0
 
CodeCruiserCommented:
What is the error?
0
 
Jack_JonesAuthor Commented:
Thank you CodeCruiser

Dim sb As New System.Text.StringBuilder
        Dim dDifference As New DataTable
        For Each col As DataColumn In dTable.Columns
            dDifference.Columns.Add(col.ColumnName, col.DataType)
        Next
        If dTable.Rows.Count < reportData.Rows.Count Then
            For i As Integer = 0 To dTable.Rows.Count - 1
                reportData.DefaultView.RowFilter = "SKU='" & Convert.ToString(dTable.Rows(i).Item(0)) & "'"
                If reportData.DefaultView.Count = 0 Then
                    Dim drow As DataRow = dDifference.NewRow
                    For j As Integer = 0 To dTable.Columns.Count - 1
                        drow(j) = dTable.Rows(i).Item(j)
                    Next
                    dDifference.Rows.Add(drow)
                End If
            Next
        Else
            For i As Integer = 0 To reportData.Rows.Count - 1
                dTable.DefaultView.RowFilter = "SKU=" & reportData.Rows(i).Item(0)
                If dTable.DefaultView.Count = 0 Then
                    sb.AppendLine(reportData.Rows(i).Item(0))
                End If
            Next
        End If

Open in new window

0
 
CodeCruiserCommented:
You can clean the code a bit


Dim dDifference As New DataTable
        For Each col As DataColumn In dTable.Columns
            dDifference.Columns.Add(col.ColumnName, col.DataType)
        Next
            For i As Integer = 0 To dTable.Rows.Count - 1
                reportData.DefaultView.RowFilter = "SKU='" & Convert.ToString(dTable.Rows(i).Item(0)) & "'"
                If reportData.DefaultView.Count = 0 Then
                    Dim drow As DataRow = dDifference.NewRow
                    For j As Integer = 0 To dTable.Columns.Count - 1
                        drow(j) = dTable.Rows(i).Item(j)
                    Next
                    dDifference.Rows.Add(drow)
                End If
            Next

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now