我正在构建一个小型 VB 应用程序,它查询 MSSQL 数据库,然后在列表框中显示这些结果。有一个 TextBox (TextBox1),用户将在其中输入一个 CharName,该 CharName 将用于选择数据库中的 CharName,以仅返回该用户的结果。我目前将 sql 查询编码到 Button1 中。
所以我需要帮助的是从 TextBox1 获取输入并将 sql 查询中的 Chars.CharName 替换为用户提供的输入,以便在单击按钮时执行查询并使用结果填充 ListBox1。
顺便说一句,我是 VB 的菜鸟(显然)。
到目前为止我的代码是:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox1_Text(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim sqlquery As String
sqlquery = ("SELECT Chars.CharName, CharItems.Type, CharItems.TypeID, CharItems.ItemName, CharItems.Bag, CharItems.Slot, CharItems.ItemUID, CharItems.Craftname, CharItems.Gem1, CharItems.Gem2, CharItems.Gem3, CharItems.Gem4, CharItems.Gem5, CharItems.Gem6 FROM Chars INNER JOIN CharItems ON Chars.CharID = CharItems.CharID WHERE ([CharName] = '" + TextBox1.Text + "'")
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
End Class