大家好我在我的ViewProductsInventory
(我的MainForm
ShowDialog
中调用了此代码):
Private Sub ViewProductsInventory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Tb_inventory_datesTableAdapter.Fill(Me.InventorySysDataSet.tb_inventory_dates)
Dim inventory_date As Date
inventory_date = Me.cboInventoryDate.Text
End Sub
Public Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim inventory_date As String
inventory_date = Me.cboInventoryDate.Text
'this part populates my datagridview1
Me.SP_GetInventoryTableAdapter.Fill(Me.InventorySysDataSet.SP_GetInventory, inventory_date)
End Sub
单击编辑按钮后,将执行EditForm.ShowDialog()
在我的EditForm中,记录将被更新,之后将触发ViewProductsInventory.btnSearch_Click( ViewProductsInventory.btnSearch, EventArgs.Empty)
然后错误“从字符串转换”“到'类型'日期'无效”发生。
我尝试了Msgbox(Me.cboInventoryDate.Text)
并且没有返回任何内容。我假设我的cboInventoryDate
目前没有填充,因此当btnSearch_Click
被触发时,它什么都没有收到。
我该如何解决这个问题?请帮助我。 TIA!
答案 0 :(得分:2)
在btnSearch_Click
事件中尝试这样的事情:
If Me.cboInventoryDate.Items.Count > 0 then
Me.cboInventoryDate.SelectedIndex = 0
inventory_date = Me.cboInventoryDate.Text
'this part populates my datagridview1
Me.SP_GetInventoryTableAdapter.Fill(Me.InventorySysDataSet.SP_GetInventory, inventory_date)
End If