【发布时间】:2018-06-16 20:27:36
【问题描述】:
我正在制作一个库存管理系统,作为我大学项目的一部分。我有一个搜索栏,结果被输出到一个列表框中。当点击搜索到的产品时,用户将被带到一个新表单,他们将能够在其中查看产品信息,例如产品名称、价格、数量、库存。用户也可以删除和添加库存。我在下面提供了一个屏幕截图。
我是 Visual Studio 的新手,我的问题是我不确定如何在文本框中显示产品信息,请有人帮忙。
这是我目前在 Form4 中的代码,它是包含搜索结果和列表框的主页。
'Importing System.Data.OleDb, this is needed for connection with database and is needed for database requirements.
Imports System.Data.OleDb
'This is the homepage
Public Class FrmHomePage
'this code runs when the user searches for a certain product - " the search button event"
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
'The code below is used to open the database connection.
Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\jacob\Desktop\MS Office\project.mdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM tblProduct WHERE productID LIKE '" & txtSearch_Bar.Text & "'", con)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
'This if statement makes sure that the product the user is searching for is inside the database, if it isnt then a "no matches" message is displayed.
If Not sdr.HasRows Then
MessageBox.Show("No Matches")
Exit Sub
End If
'this clears the listbox so, if the user searches same product again, it wouldn't duplicate.
lstbSearchResult.Items.Clear()
'Checking for the item in database and outputting it to the listbox.
While (sdr.Read())
lstbSearchResult.Items.Add(sdr("ProductID"))
End While
'closing the database connection
con.Close()
End Sub
'this private sub is basically a side menu which slides out when the user clicks the button "menu".
'Inside the menu the user will have different options such As settings, About us, And more.
Private Sub btnMenu_Click(sender As System.Object, e As System.EventArgs) Handles btnMenu.Click
PnlSide_Menu.Location = New Point(-183, 0)
Do Until PnlSide_Menu.Location.X = -10
PnlSide_Menu.Location = New Point(PnlSide_Menu.Location.X + 1, 0)
Loop
Do Until PnlSide_Menu.Location.X = 0
PnlSide_Menu.Location = New Point(PnlSide_Menu.Location.X + 1, 0)
Refresh()
System.Threading.Thread.Sleep(20)
Loop
End Sub
'private sub for closing the the side menu/side bar.
Private Sub BtnBack_Click(sender As System.Object, e As System.EventArgs) Handles BtnBack.Click
PnlSide_Menu.Location = New Point(0, 0)
Do Until PnlSide_Menu.Location.X = -170
PnlSide_Menu.Location = New Point(PnlSide_Menu.Location.X - 1, 0)
Refresh()
Loop
Do Until PnlSide_Menu.Location.X = -183
PnlSide_Menu.Location = New Point(PnlSide_Menu.Location.X - 1, 0)
System.Threading.Thread.Sleep(20)
Loop
End Sub
'this is the logout button function.
'when clicked the user will be taken back to the login page.
Private Sub btnLogOut_Click(sender As Object, e As EventArgs) Handles btnLogOut.Click
Me.Close()
FrmLogin.Show()
End Sub
Private Sub lstbSearchResult_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstbSearchResult.SelectedIndexChanged
End Sub
下面的这段代码是我打算做上面提到的事情的地方。
'Click event of the result in listbox.
Private Sub lstbSearchResult_Click(sender As Object, e As EventArgs) Handles lstbSearchResult.Click
Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\jacob\Desktop\MS Office\project.mdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM tblProduct WHERE productID LIKE '" & txtSearch_Bar.Text & "'", con)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
con.Close()
frmProductForm.Show()
End Sub
End Class
【问题讨论】:
-
您可能想研究数据绑定。您还应该阅读How to Ask 并选择tour。
i am unsure how ...不是问题,只是表示你没有做足够的研究。这不是一个教程网站 -
你怎么了?我不明白。每次你是第一个看到我的帖子的人,你甚至帮不上忙,而是批评我的帖子。说真的,如果可以,请提供帮助。我不是专业人士,也不是什么都做对了,我犯了一些错误,我是初学者。所以请停止劝阻。顺便说一句,感谢“数据绑定”@Plutonix
-
第一个看到我的帖子的人,你甚至帮不上忙,然后顺便说一句,感谢“数据绑定”。
-
网站不是这样运作的。 应该不鼓励发布过于宽泛、偏离主题和/或研究不足的帖子(通过投票)。当然,你可以通过做更多的研究和提出更好的问题来减轻很多这种情况。阅读How to Ask,获取tour,或者访问help center了解详情。除了一篇帖子之外,所有帖子的评分均为负分,很快这将限制您发布任何内容的能力。
-
理想情况下,库存管理(库存)数据库不会保存汇总数据。输入进出库存交易,然后根据原始数据记录计算净余额。您的项目需要使用 VB.net 吗?
标签: sql vb.net forms ms-access listbox