Jack_Jones
asked on
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!
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!
ASKER
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.
Have you started on this? What specific part you need help with? You work on saturdays?
ASKER
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.
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.
Compare the datagridview2 & 3, export data difference using xml for the report viewer to sort.
datatable.dataset.writexml
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
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.
ASKER
I was trying reportData.DataSet.WriteXM L("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.
For gridviews, you can do something like
For i As Integer = 0 to DataGridView3.Rowcount - 1
dTable4.DefaultView.RowFil ter = "columnname=" & DataGridView3.Item(columni ndex, i).Value
if dTable4.DefaultView.Count = 0 Then
'code to insert row as in http:#36970651
End If
Next
For i As Integer = 0 to DataGridView3.Rowcount - 1
dTable4.DefaultView.RowFil
if dTable4.DefaultView.Count = 0 Then
'code to insert row as in http:#36970651
End If
Next
ASKER
Well can't seem to make that work, got a blue squigly line that I can resolve,
DatagridView3.Item(columni ndex, i).value <- columnindex causes issue
-------------------------- -------
Have to figure something out it's crunch time for me =\
DatagridView3.Item(columni
--------------------------
Have to figure something out it's crunch time for me =\
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.
ASKER
DefaultView.RowFilter = "columnname="
Cannot find column [columnname].
Cannot find column [columnname].
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
What is the error?
ASKER
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
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
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
http://www.codeproject.com/KB/cs/CreatingCrystalReports.aspx