用这样的 sql
Dim sql = "SELECT * FROM TablePDF order by NameX asc"
我遍历我的数据库的名称并用数据制作一个 iTextsharp 表。
While (readerProtocoloTablePDF.Read())
NameXPDF = (readerProtocoloTablePDF("NameX"))
...
...
...
如果记录看起来像
奥迪
阿尔法罗密欧
阿斯顿·马丁
宝马
布加迪
当我阅读“Aston Martin”时,我需要知道这是以“A”开头的姓氏,因此该记录的行将有一个特殊的底线来关闭 A 字母
这是因为我需要更改最后一条记录的边框或单元格,并在新字母开始前插入一个空白页
选项是
cellHRectangleBorder = 12 'just left and right border
cellHRectangleBorder = 14 'lef, right AND BOTTOM border (Last record of a letter)
在 table 上我使用类似的代码
cellH3.Border = cellHRectangleBorder
如果它是一封信的最后一条记录,我也需要一个空白页
pdfDoc.NewPage()
我知道如何在阅读 BMW 时检测字母的变化,但这是在 A 结束之后。
有没有办法在不破坏普通 sql 阅读器的情况下只获取下一条记录的一个字段?
或者我需要一个循环在另一个循环中,或者可能首先是一个 While - reader 循环,只是为了检测一个字母何时发生变化,然后是另一个 While 阅读器循环来创建表格,预先知道每个字母的字段数?
最佳答案
我只能建议一个伪代码,你应该在你的实际代码中用真实的变量名进行转换,但本质上你在阅读它时不会添加一行,而是在下面的阅读中添加它
Dim lastName as String = ""
Dim lastLetter As string = ""
While (readerProtocoloTablePDF.Read())
' Read the Name and store it
NameXPDF = (readerProtocoloTablePDF("NameX"))
Dim curLetter = NameXPDF(0).ToString()
' Skip first loop
if lastLetter <> "" Then
' After the first loop check if there is a change in the first letter
if lastLetter <> curLetter then
' Yes, add the previous loop name as the last line and jump page
AddTheLastLineOfThePage(lastName)
NewPage()
else
' No add a normal line with the previous name read
AddNormalLine(lastName)
End if
End if
' Save the current name read for the next loop
lastName = NameXPDF
lastLetter = lastName(0).ToString()
Loop
' Do not forget to add the last line
AddTheLastLineOfThePage(lastName)
关于vb.net - SQLiteDataReader 从下一条记录中获取一个字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40428382/