Reset pagesize for each record iText - asp.net

I am trying to reset the pagesize of each record in pdf, which is the total page
(1 of pagesize
2 of pagesize.......)
The 1st blockcode work for 1 single record but then when it come to multiple record it showed:
1 of 0 //1st record
2 of 0
1 of 0 //2nd record
.......
I think there is something to do with document.setPageSize() but it is boolean and belong to Rectangle.
Please help me solve this problem.
Thank.
Public Overrides Sub onEndPage(ByVal writer As PdfWriter, ByVal document As Document)
Dim page As Rectangle = document.getPageSize()
Dim cb As PdfContentByte = writer.getDirectContent()
Dim arialbasefont As BaseFont = arial.getBaseFont
Dim pg As Rectangle = document.getPageSize()
Dim pageNumberText As String = "Page " & writer.getPageNumber() & " of "
Dim timeStampText As String = Now.ToString
Dim pageNumberTextLength As Double = arialbasefont.getWidthPoint(pageNumberText, footerFontSize)
Dim timeStampTextLength As Double = arialbasefont.getWidthPoint(timeStampText, footerFontSize)
Dim pageNumberTextLeft As Double = 20
Dim templateLeft As Double = pageNumberTextLeft + pageNumberTextLength
Dim pageNumberTextBottom As Double = 5 + footerFontSize
cb.beginText()
cb.setFontAndSize(arialbasefont, footerFontSize)
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, pageNumberText, pageNumberTextLeft, pageNumberTextBottom, 0)
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, Now, pg.urx - (timeStampTextLength + 20), pageNumberTextBottom, 0)
cb.endText()
cb.addTemplate(tpl, templateLeft, pageNumberTextBottom)
End Sub
For Each ProjectID In array
Dim rptRequestReportObj As New rptRequestReport2
rptRequestReportObj.Report(document, ProjectID)
document.newPage()
document.setPageCount(1)
Next ProjectID

Related

Can't find dynamically created TD in code behind

I have created a dynamic table in my code behind which loads up on page load. I have created a button which when clicked I need to add a <div> to specific <td> in the table. However, it is not finding my <td> element using the id. What am I doing wrong?
Function CalendarRefresh(Day As Integer, MonthDays As Integer)
Dim iDay As Integer = 1
Dim TableID As Integer
Dim TDCount As Integer = 0
Dim FullTDCount As Integer = 0 '42
Dim StringHtml As New StringBuilder
Dim DaysInMonth As Integer = MonthDays
clsWork.GetUnscheduledWork()
Dim ClientName = "Terence Creighton" ' Test Replace with DB Value
Dim JobName = "Install Job"
' Top structure of table
StringHtml.Append("<table id='calendar' runatserver='server'>")
StringHtml.Append("<tr class='weekdays'>")
StringHtml.Append("<th scope='col'>Sunday</th>")
StringHtml.Append("<th scope='col'>Monday</th>")
StringHtml.Append("<th scope='col'>Tuesday</th>")
StringHtml.Append("<th scope='col'>Wednesday</th>")
StringHtml.Append("<th scope='col'>Thursday</th>")
StringHtml.Append("<th scope='col'>Friday</th>")
StringHtml.Append("<th scope='col'>Saturday</th>")
StringHtml.Append("</tr>")
StringHtml.Append("<tr Class='days'>")
If Day > 1 Then
Do While iDay < (Day)
' add Previous month style
StringHtml.Append("<td class='day other-month'>")
StringHtml.Append("</td>")
iDay = iDay + 1
TDCount = TDCount + 1
FullTDCount = FullTDCount + 1
Loop
End If
For i As Integer = 1 To DaysInMonth
If TDCount = 7 Then
StringHtml.Append("</tr>")
StringHtml.Append("<tr class='days'>")
TDCount = 0
FullTDCount = FullTDCount + 1
i = i - 1
Else
StringHtml.Append("<td class='day' ")
StringHtml.Append("id='")
StringHtml.Append(i)
StringHtml.Append("' Runat='server'>")
StringHtml.Append("<div class='date'>")
StringHtml.Append(i)
StringHtml.Append("</div>")
'StringHtml.Append("<div id='")
'StringHtml.Append(i)
'StringHtml.Append("' Runat='server'>")
'StringHtml.Append("<div Class='panel panel-primary' draggable='true'>")
'StringHtml.Append("<div Class='panel-heading'>")
'StringHtml.Append(ClientName)
'StringHtml.Append("</div>")
'StringHtml.Append("<div Class='panel-body'>")
'StringHtml.Append(JobName)
'StringHtml.Append("</div>")
'StringHtml.Append("</div>")
StringHtml.Append("</div>")
StringHtml.Append("</td>")
TDCount = TDCount + 1
FullTDCount = FullTDCount + 1
End If
Next
StringHtml.Append("</tr>")
StringHtml.Append("</table>")
Return StringHtml.ToString
End Function
Public Sub ScheduledJobs()
Dim StringHtml As New StringBuilder
Dim ClientName As String
Dim JobName As String
Dim Work = clsWork.GetUnscheduledWork()
For Each i As Integer In Work.Rows.Count
ClientName = Work.Rows(i).Items("ClientName").ToString
JobName = Work.Rows(i).Items("JobName").ToString
ID = i.ToString
StringHtml.Append("<div class='panel panel-primary' draggable='true' ondragstart='OnDragStart' ondrop='OnDrop' ")
StringHtml.Append("id='")
StringHtml.Append(ID)
StringHtml.Append("'>")
StringHtml.Append("<div class='panel-heading'>")
StringHtml.Append(ClientName)
StringHtml.Append("</div>")
StringHtml.Append("<div class='panel-body'>")
StringHtml.Append(JobName)
StringHtml.Append("</div>")
Next
Dim MyTable As HtmlTable = Page.FindControl("calendar")
Dim MyCell As HtmlTableCell
MyCell.ID = "19"
If MyCell Is Nothing Then
messageResponse = "Tablecell not found"
Else
MyCell.InnerHtml = StringHtml.ToString
End If
End Sub
Private Sub cmdLoadJobs_ServerClick(sender As Object, e As EventArgs) Handles cmdTry.ServerClick
ScheduledJobs()
End Sub
I am expecting find the td with the ID and add the html string in the ("td Element").innerhtml. I have tried various combinations of findcontrol but all turns up empty
You have to create real dynamic controls. Here a very basic example of how to interact with a dynamically created table.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
//do not create dynamic control in an ispostback check
}
//create some table and it's rows and cells. note the assignent of an ID
Table table = new Table()
{
ID = "MyTable1"
};
TableRow row = new TableRow()
{
ID = "MyRow1"
};
TableCell cell = new TableCell()
{
ID = "MyCell1",
Text = "My 1st cell"
};
//add the cell to the row
row.Controls.Add(cell);
//add the row to the table
table.Controls.Add(row);
//add the table to the page
PlaceHolder1.Controls.Add(table);
}
protected void Button1_Click(object sender, EventArgs e)
{
//use findcontrol to locate the cell
TableCell cell = PlaceHolder1.FindControl("MyCell1") as TableCell;
//interact with it
cell.Text = "Cell Found!";
}
I see this:
StringHtml.Append("<table id='calendar' runatserver='server'>")
While it's certainly fine to push raw html to a page in the browser by building an html string, you cannot create server controls this way. You won't be able to access anything in that html from your code behind. The runat='server' part is first of all keyed wrong, but would be worthless even if written correctly. By the time you're in the Page_Load event, everything that looks for the runat='server' attribute has already finished.

How do I get the value of a multiple dynamically generated dropdownlist?

I'm doing a small website for school and I got stuck on this problem. How can I get the value of each dropdownlist? The dropdownlist are dynamically generated by code. I did the same with the textboxes and it works perfectly, but with the values of the dropdownlists doesn't work, I mean, I don't get the values back. What should I do?
Partial Class Opties
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim aantalMensen As Integer = CInt(Session("aantalVolwassenen")) + CInt(Session("aantalKinderen")) + CInt(Session("aantalBabys"))
Session("aantalMensen") = CStr(aantalMensen)
For x As Integer = 1 To aantalMensen
'Passagiers info
Dim aanhef As New DropDownList()
Dim aanhefSelectie As ListItem
aanhefSelectie = New ListItem("Dhr.", "Dhr.")
aanhef.Items.Add(aanhefSelectie)
aanhefSelectie = New ListItem("Mevr.", "Mevr.")
aanhef.Items.Add(aanhefSelectie)
Dim voornaam As New TextBox With {.ID = "txtVoornaam" & x}
Dim achternaam As New TextBox With {.ID = "txtAchternaam" & x}
Dim lt As New Literal()
Dim Endlt As New Literal()
Dim space As New Literal()
lt.Text = "<p>Persoon " + CStr(x) + ":"
Endlt.Text = "</p> "
space.Text = "<br />"
gegevensPassagiers.Controls.Add(lt)
gegevensPassagiers.Controls.Add(aanhef)
gegevensPassagiers.Controls.Add(voornaam)
gegevensPassagiers.Controls.Add(achternaam)
gegevensPassagiers.Controls.Add(Endlt)
gegevensPassagiers.Controls.Add(space)
Next
For i As Integer = 1 To aantalMensen
'Bagage DropDownlist
Dim aantalKG As New DropDownList With {.ID = "ddlBagage" & i}
Dim KGselectie As ListItem
KGselectie = New ListItem("Geen", "Geen")
aantalKG.Items.Add(KGselectie)
KGselectie = New ListItem("15kg", "15kg")
aantalKG.Items.Add(KGselectie)
KGselectie = New ListItem("25kg", "25kg")
aantalKG.Items.Add(KGselectie)
KGselectie = New ListItem("35kg", "35kg")
aantalKG.Items.Add(KGselectie)
aantalKG.AutoPostBack = True
Dim lt As New Literal()
Dim Endlt As New Literal()
Dim space As New Literal()
lt.Text = "<p>Persoon " + CStr(i) + ":"
Endlt.Text = "</p> "
space.Text = "<br />"
bagageDIV.Controls.Add(lt)
bagageDIV.Controls.Add(aantalKG)
bagageDIV.Controls.Add(Endlt)
bagageDIV.Controls.Add(space)
Next
Dim index As Integer = 1
If IsPostBack Then
For Each key As String In Request.Form.Keys
If key.Contains("txtVoornaam") Then
Session("Voornaam" & index) = CType(Request.Form(key), String)
index += 1
End If
If key.Contains("txtFamilienaam") Then
Session("Familienaam" & index) = CType(Request.Form(key), String)
index += 1
End If
If key.Contains("ddlBagage") Then
Session("Bagage" & index) = CType(Request.Form(key), String)
index += 1
End If
Next
End If
End Sub
You can use JavaScript for get selected value of dropdownlists.
for example:
var e = document.getElementById("aanhef ");
var Selectedvalue = e.options[e.selectedIndex].value;
Well, after testing some methodes and attributes and other stuff.... I found an easy solution for my problem (also thanks for helping #MaCron).
Here is the code:
For Each aantalKG As DropDownList In bagageDIV.Controls.OfType(Of DropDownList)()
Session("Bagage" & index) = aantalKG.SelectedValue
index += 1
Next

Index was out of range. Must be non-negative and less than the size of the collection - chart databind

I'm trying to build a datatable and then bind it to a gridview and chart object. The gridview appears fine but when I build the x,y array and bind them to the chart object I get the error above.
I've read many forums to understand that the index is looking at a field that is out of range but I've queried in the immediate window all the fields and the are clearly values there. There error occurs as soon as I bind it to the chart object and I don't know why the chart object doesn't just display properly.
This is my aspx codebehind:
Dim dt As DataTable = New DataTable()
dt.Columns.Add("CompanyName")
dt.Columns.Add("Amount")
dt.Columns.Add("Proportion")
Using DBContext As New fundmatrixEntities
Dim queryUnits = (From c In DBContext.Units Where c.SavingApplicationId = savAppId Select New With {.LoanAppId = c.LoanApplicationId}).Distinct().ToList()
Dim companyName As String = ""
Dim savingsAmount As String = ""
Dim totalProportion As String = ""
Dim totalSavingsAmount As String = ""
For Each loan In queryUnits
If Not loan.LoanAppId Is Nothing Then
companyName = classSQLDirect.ExecQuery("SELECT companyname FROM companyprofile where loanapplicationid='" & loan.LoanAppId.ToString & "'")
savingsAmount = classSQLDirect.ExecQuery("SELECT SUM(Amount) from unit where SavingApplicationId='" & savAppId.ToString & "' and LoanApplicationId='" & loan.LoanAppId.ToString & "'")
totalSavingsAmount = classSQLDirect.ExecQuery("SELECT amount FROM SavingApplication WHERE SavingApplicationId='" & savAppId.ToString & "'")
totalProportion = ((savingsAmount / totalSavingsAmount) * 100) & "%"
dt.Rows.Add(companyName, savingsAmount, totalProportion)
End If
Next
gvwBusinesses.DataSource = dt
gvwBusinesses.DataBind()
End Using
Dim x As String() = New String(dt.Rows.Count - 1) {}
Dim y As String() = New String(dt.Rows.Count - 1) {}
For i As Integer = 0 To dt.Rows.Count - 1
x(i) = dt.Rows(i)(0).ToString()
y(i) = dt.Rows(i)(2).ToString()
Next
chart1.Series(0).Points.DataBindXY(x, y)
chart1.Series(0).ChartType = SeriesChartType.Pie
The code errors on the line
chart1.Series(0).Points.DataBindXY(x, y)

delaying file read/write till it's done being used?

I have a vb.net MVC3 Razor app that generates PDF files. The problem is that if 2 seperate users click the print button at the same time it throws the following exception..:
The process cannot access the file 'E:\web\xxxxxxxxxxsonl\PDF_Files\MailingLables.pdf' because it is being used by another process.
All of the controller actions to do with printing are basically like below:
Function Ind_Cert(ByVal firstName As String, ByVal lastname As String, ByVal classRef As String)
Dim _Attendance As attendance = db.attendances.Where(Function(f) f.Completed_Class = "Completed" And f.firstName = firstName And f.lastName = lastname).FirstOrDefault
If Not IsNothing(_Attendance) Then
Dim _reg_classes As List(Of reg_classes) = db.reg_classes.ToList
Dim _registrants As List(Of reg_info) = db.reg_info.ToList
Dim _courses As List(Of cours) = db.courses.ToList
Dim _Board As List(Of board_members) = db.board_members.ToList
Dim Board_Member As board_members = _Board.Where(Function(f) f.Official_Cap = "xxxxxx President").FirstOrDefault
Dim RecordId As Integer = 0
Dim conf_info As conf_info = db.conf_info.Single(Function(r) r.id = 0)
Dim conf_num As Integer = conf_info.conf_number
Dim _conf_num As String = conf_num.ToString
Dim Length As Integer
Dim _prefix As String = String.Empty
If Str(conf_num) <> "" Then
Length = Str(conf_num).Length
End If
Dim Divisor As Integer = 10 ^ (Length - 1)
Dim conf_num_start As Integer = 0
Dim Digits(Length - 1) As Integer
While (conf_num > 10)
'Extract the first digit
Digits(conf_num_start) = Int(conf_num / Divisor)
'Extract remainder number - and store it back in Num
conf_num = conf_num Mod Divisor
'Decrease Divisor's value by 1/10th units
Divisor /= 10
'Increment Index
conf_num_start += 1
End While
If conf_num = 0 Or 4 Or 5 Or 6 Or 7 Or 8 Or 9 Then _prefix = "th"
If conf_num = 1 Then _prefix = "st"
If conf_num = 2 Then _prefix = "nd"
If conf_num = 3 Then _prefix = "rd"
Dim pdfpath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
Dim imagepath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
Dim _PdfName As String = "Cert_" + lastname + ".pdf"
Dim doc As New Document
doc.SetPageSize(iTextSharp.text.PageSize.LETTER.Rotate())
doc.SetMargins(1, 1, 1, 1)
Dim _pageCounter As Integer = 0
Dim Californian As BaseFont = BaseFont.CreateFont(Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\Fonts\" + "CALIFB.TTF", BaseFont.CP1252, BaseFont.EMBEDDED)
Dim Copper As BaseFont = BaseFont.CreateFont(Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\Fonts\" + "COPRGTB.TTF", BaseFont.CP1252, BaseFont.EMBEDDED)
Dim Bold_Times As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, False)
Dim BF_Times As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, False)
Dim F_Name As New Font(BF_Times, 16, Font.BOLD, BaseColor.BLACK)
Dim _Parking_Name As New Font(BF_Times, 18, Font.NORMAL, BaseColor.BLACK)
Dim _Parking_Date As New Font(BF_Times, 24, Font.BOLD, BaseColor.BLACK)
'**********************************Y lines for trial***********************************
Dim y_line1 As Integer = 670
Dim _Counter As Integer = 1
Dim _Page As String = 1
Dim _CertJpg As Image = Image.GetInstance(imagepath + "/cert.jpg")
Dim imageWidth As Decimal = _CertJpg.Width
Dim imageHeight As Decimal = _CertJpg.Height
Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(pdfpath + _PdfName, FileMode.Create))
doc.Open()
Dim cb As PdfContentByte = writer.DirectContent
If _Attendance.Completed_Class = "Completed" Then
Dim _confInfo As conf_info = db.conf_info.Single(Function(a) a.id = 0)
Dim year As String = Right(_confInfo.conf_start_date, 4)
Dim _reg As reg_info = db.reg_info.Single(Function(b) b.id = _Attendance.reg_id)
Dim name As String = _reg.first_name + " " + _reg.last_name
Dim _dates As String = _confInfo.conf_start_date + " - " + _confInfo.conf_end_date
Dim _course As cours = db.courses.Single(Function(c) c.course_ref = _Attendance.course_ref)
Dim _className As String = _course.course_title.ToString
Dim _hours As String = _course.course_hours
Dim _certName As String = Board_Member.First_Name + " " + Board_Member.last_name
_CertJpg.Alignment = iTextSharp.text.Image.UNDERLYING
_CertJpg.ScaleToFit(792, 611)
doc.Add(_CertJpg)
cb.BeginText()
cb.SetFontAndSize(Californian, 36)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "CERTIFICATE OF COMPLETION", 396, 397.91, 0)
cb.SetFontAndSize(Bold_Times, 22)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, name, 396, 322.35, 0)
cb.SetFontAndSize(Bold_Times, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _hours + " Hours", 297.05, 285.44, 0)
cb.SetFontAndSize(Bold_Times, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _dates, 494.95, 285.44, 0)
cb.SetFontAndSize(Bold_Times, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Class Attended: " + " " + _Attendance.course_ref + " -- " + _className, 396, 230.34, 0)
cb.SetFontAndSize(Copper, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _conf_num + _prefix + " Annual Conference " + _dates, 396, 193.89, 0)
cb.SetFontAndSize(Bold_Times, 13)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _certName, 396, 175.69, 0)
cb.SetFontAndSize(Bold_Times, 10)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "xxxxxxx President", 396, 162.64, 0)
cb.EndText()
End If
doc.Close()
Return _PdfName
Else
Return "Fail"
End If
End Function
This error happens like I said any time 2 users try to generate a PDF file at the same time. Anyone know of a fix for this issue? Google has turned up countless pages about someone can't delete a file in windows because its being used. But that isn't much help.. Any ideas???
You can pretty much do two things.
Add a lock on the file and block the second (and third and fourth, etc) until the lock is cleared
Create a unique file for each instance.
I'd recommend #2. You can keep the same file name, just put the file in a unique directory. A GUID is usually the easiest for me:
Dim pdfpath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
pdfPath = Path.Combine(pdfPath, Guid.NewGuid.ToString())
Directory.CreateDirectory(pdfPath)
Then change your return to include the path created above.
Can you create the PDF file with a random file name to avoid the conflict in the first place?
Wrap your file access code in a lock.
lock (this)
{
//Write file
}
See Lock on MSDN

compare the content of 2 gridviews in one aspx page

we need to compare the content of 2 identical gridviews and extract rows that differ in a third gridview, is this doable?
i tried a lot but faced no luck, please help me.
at our office we take daily backup of ASP.net application ms access backend
for the next few days we need to evaluate the changes made to records in the database tables
at the end of each day i want to compare 2 access databases first database is the backup of yesterday and second database is the backup of today
i thought of the following algorithm, please read carefully and tell me how to proceed to compare the datatables / gridviews
i need to display th rows / cells containing the differences / updates / deleted data
comparing two ms access backend databases of an asp.net web application
my team and myseld figured it out
Imports System.Data
Imports System.Data.OleDb
Partial Class MoKoTrack
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myDB = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|databaseName.mdb;Persist Security Info=True")
Session("CurrentDB") = myDB
myDB.open()
Dim mytables = myDB.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, New Object() {})
Dim CurrentTable As String
For i = 1 To mytables.Rows.Count
CurrentTable = mytables.Rows(i - 1).Item(2).ToString
If CurrentTable.Contains("Backup") Then CompareTable(CurrentTable, mytables.Rows(i - 1).Item(3).ToString)
Next i
' Dim myGrid As New GridView
'myGrid.DataSource = mytables
'myGrid.DataBind()
'Me.Form.Controls.Add(myGrid)
'myDB.Close()
End Sub
Sub CompareTable(ByVal BackupTableName As String, ByVal myPrimKey As String)
Dim OriginalTable As New DataTable
Dim BackupTable As New DataTable
Dim ModificationsTable As New DataTable
Dim AddedTable As New DataTable
Dim DeletedTable As New DataTable
Dim myDB = Session("CurrentDB")
Dim FinalSQLString = "SELECT * FROM [" + BackupTableName + "]"
Dim myDBCommand = New OleDbCommand(FinalSQLString, myDB)
Dim myReader As IDataReader = myDBCommand.ExecuteReader()
BackupTable.Load(myReader)
Dim OriginalTableName = Left(BackupTableName, Len(BackupTableName) - 6)
Dim FinalSQLString2 = "SELECT * FROM [" + OriginalTableName + "]"
Dim myDBCommand2 = New OleDbCommand(FinalSQLString2, myDB)
'Generate a temporary reader to get the number of cases
Dim myReader2 As IDataReader = myDBCommand2.ExecuteReader()
OriginalTable.Load(myReader2)
Dim myPrimColumn(0) As DataColumn
myPrimColumn(0) = OriginalTable.Columns(myPrimKey)
OriginalTable.PrimaryKey = myPrimColumn
Dim myPrimColumn2(0) As DataColumn
myPrimColumn2(0) = BackupTable.Columns(myPrimKey)
BackupTable.PrimaryKey = myPrimColumn2
AddedTable = OriginalTable.Clone
DeletedTable = OriginalTable.Clone
ModificationsTable = OriginalTable.Clone
ModificationsTable.PrimaryKey = Nothing
Dim CurrentVal As String
For i = 0 To OriginalTable.Rows.Count - 1
CurrentVal = OriginalTable.Rows(i).Item(myPrimKey).ToString
Dim foundRow As DataRow = BackupTable.Rows.Find(CurrentVal)
If foundRow IsNot Nothing Then
For t = 0 To OriginalTable.Columns.Count - 1
If Not foundRow.Item(t).ToString = OriginalTable.Rows(i).Item(t).ToString Then
ModificationsTable.ImportRow(OriginalTable.Rows(i))
'ModificationsTable.Rows(ModificationsTable.Rows.Count - 1).Item(t) = ModificationsTable.Rows(ModificationsTable.Rows.Count - 1).Item(t) & "Modified"
ModificationsTable.ImportRow(foundRow)
End If
Next
Else
AddedTable.ImportRow(OriginalTable.Rows(i))
End If
Next
For i = 0 To BackupTable.Rows.Count - 1
CurrentVal = BackupTable.Rows(i).Item(myPrimKey).ToString
Dim foundRow As DataRow = OriginalTable.Rows.Find(CurrentVal)
If foundRow Is Nothing Then
DeletedTable.ImportRow(OriginalTable.Rows(i))
End If
Next
If AddedTable.Rows.Count > 0 Then
Dim myLabel As New Label
myLabel.Text = "<br/> The following records were added to table " & OriginalTableName & "<br/> <br/>"
Me.form1.Controls.Add(myLabel)
Dim myGrid As New GridView
myGrid.DataSource = AddedTable
myGrid.DataBind()
Me.form1.Controls.Add(myGrid)
End If
If ModificationsTable.Rows.Count > 0 Then
Dim myLabel As New Label
myLabel.Text = "<br/> The following records were modified in table " & OriginalTableName & "<br/> <br/>"
Me.form1.Controls.Add(myLabel)
Dim myGrid As New GridView
myGrid.DataSource = ModificationsTable
myGrid.DataBind()
Me.form1.Controls.Add(myGrid)
End If
If DeletedTable.Rows.Count > 0 Then
Dim myLabel As New Label
myLabel.Text = "<br/> The following records were deleted from table " & OriginalTableName & "<br/> <br/>"
Me.form1.Controls.Add(myLabel)
Dim myGrid As New GridView
myGrid.DataSource = DeletedTable
myGrid.DataBind()
Me.form1.Controls.Add(myGrid)
End If
End Sub
End Class
I usually compare it using LINQ
This will give you a head start
var SearchResults1 = from u in YourDB.YourUserTable1
orderby u.YourColumn
select u;
GridView1.DataSource = SearchResults1;
GridView1.DataBind();
var SearchResults2 = from u in YourDB.YourUserTable2
orderby u.YourColumn
select u;
GridView2.DataSource = SearchResults2;
GridView2.DataBind();
var SearchResults3 = from u1 in SearchResults2
where !(from u2 in SearchResults1
select u2.YourTablePrimaryKey).Contains(u1.YourTablePrimaryKey)
orderby u1.YourColumn
select u1;
GridView3.DataSource = SearchResults3;
GridView3.DataBind();
You can further elaborate SearchResults 3 if you want like comparing whats in SearchResults1 but not in SearchResults2 and vice versa

Resources