我是编程乐趣,一个10年.Net开发经验老程序员,点击右上方“关注”,每天为你分享开源项目和编程知识。
2024年10月04日
Imports System.Data.SQLite
Public Class MainForm
' 数据库连接字符串
Dim connectionString As String = "Data Source=mydatabase.db"
' 数据绑定的数据源
Dim bindingSource As New BindingSource()
' 分页相关的变量
Dim pageSize As Integer = 10
Dim currentPage As Integer = 1
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 初始化带有 BindingSource 的 DataGridView
dgvUsers.DataSource = bindingSource
' 加载初始页面
LoadPage(currentPage)
End Sub
Private Sub btnNextPage_Click(sender As Object, e As EventArgs) Handles btnNextPage.Click
' 加载下一页
currentPage += 1
LoadPage(currentPage)
End Sub
Private Sub btnPreviousPage_Click(sender As Object, e As EventArgs) Handles btnPreviousPage.Click
' 确保不要到达负页数
If currentPage > 1 Then
' 加载上一页
currentPage -= 1
LoadPage(currentPage)
End If
End Sub
Private Sub LoadPage(pageNumber As Integer)
' 计算当前页面的偏移量
Dim offset As Integer = (pageNumber - 1) * pageSize
' 从数据库中读取一页记录
Dim userRecords As List(Of User) = ReadUserRecords(pageSize, offset)
' 将记录绑定到 DataGridView
bindingSource.DataSource = userRecords
End Sub
Private Function ReadUserRecords(limit As Integer, offset As Integer) As List(Of User)
' 选择数据库中的一页用户的 SQL 查询
Dim query As String = #34;SELECT Username, Password FROM Users LIMIT {limit} OFFSET {offset}"
Dim userRecords As New List(Of User)()
Using connection As New SQLiteConnection(connectionString)
connection.Open()
Using command As New SQLiteCommand(query, connection)
Using reader As SQLiteDataReader = command.ExecuteReader()
' 遍历记录
While reader.Read()
Dim userRecord As New User()
userRecord.Username = reader.GetString(0)
userRecord.Password = reader.GetString(1)
userRecords.Add(userRecord)
End While
End Using
End Using
End Using
Return userRecords
End Function
End Class
' 存储检索数据的 User 类
Public Class User
Public Property Username As String
Public Property Password As String
End Class
2024年10月04日
VBA,英文全称Visual Basic for Applications,直接翻译过来叫做“可以直接使用的VB语言”。
2024年10月04日
Smtp对象提供了多种方法和属性来调整优化发送消息的过程。可以创建一个新的Smtp对象实例,如下所示:
C#: Smtp mailer = new Smtp; VB.NET: Dim mailer As New Smtp
如果SMTP服务器不需要任何身份验证,那么指定的主机名或它的IP地址就足以连接到此SMTP服务器。
2024年10月04日
以下内容介绍在C# 程序中如何将SVG图片添加到PDF文档、以及如何将SVG图片转换为PDF文档。
先下载PDF类库工具,Spire.PDF for .NET hotfix 6.5.6及以上版本(下载时,注意版本信息)。下载后,解压文件,将Bin文件夹下的Spire.Pdf.dll文件在VS中的"解决方案资源管理器"进行"添加引用"。另外,也可以通过下载。
2024年10月04日
VS022写的C#程序放到Mono底座上在Linux上运行相对比较容易,Mono可以在不同CPU结构下运行,底座上的程序也能跟着在它上面运行。 Mono和NetCore,在用不同的方式让 .NET平台上的应用程序跨到其它操作系统平台上运行。如果数据库处理交给数据库服务器去做,GUI交给gtk或web界面去做,再广泛应用其它一些so库,那语言最后越来越胶水糖了。
VBNET能用MonoIDE在Linux上写,我写个简单的例子吧。
2024年10月04日