2016-01-17 45 views
-3

出于某种原因,我的messageBox没有出现!有人可以帮助我:visual basic - MessageBox不出现

代码:

item = InputBox("What is the item?", "InputBox Test", "Type the item here.") 
If item = "shoe" Then 
    Dim connStr As String = "" 
    Dim connection As New MySqlConnection(connStr) 
    Dim READER As MySqlDataReader 
    connection.Open() 
    Dim Query As String 
    Query = "UPDATE table set item = noOfItems+1 where username= '" & Login.txtusername.Text & "'" 
    COMMAND = New MySqlCommand(Query, connection) 
    READER = COMMAND.ExecuteReader 
    If (READER.Read() = True) Then 
     Query = "select * from table where username= '" & Login.txtusername.Text & " '" 
     Dim noOfItems As Integer 
     Dim username As String 
     noOfItems = READER("noOfItems") 
     username = READER("username") 
     MessageBox.Show(username & "- The number of items you have is: " & noOfItems) 
    End If 
Else 
    MsgBox("Unlucky, Incorrect item. Please see hints. Your score still remains the same") 

感谢提前:)

+5

' “因为某些原因”“ - 这听起来像是一个出色的* *的机会,熟悉使用调试器。它允许您在执行代码时逐行执行代码,并观察变量的行为和运行时值。这将允许您确定代码实际采用的逻辑路径,以便您可以看到*为什么*它没有达到您期望的代码行。如果您能向我们提供相关信息,我们可以帮助回答这个“为什么”。但是我们无法为您在计算机上调试您的代码。 – David

+4

调试的能力是***必不可少的***。 – Plutonix

回答

0
Dim item As Object 
Dim Command As MySqlCommand 
Dim READER As MySqlDataReader 
Dim connection As MySqlConnection 
Dim Query As String 
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    Try 
     item = InputBox("What is the item?", "InputBox Test", "Type the item here.") 
     If item = "shoe" Then 
      Dim connStr As String = "" 
      Dim connection As New MySqlConnection(connStr) 
      connection.Open() 
      Query = "select * from table where username= '" & txtusername.Text & " '" 
      READER = Command.ExecuteReader 
      If READER.HasRows Then 
       Dim noOfItems As Integer 
       Dim username As String 
       noOfItems = READER("noOfItems") + 1 
       username = READER("username") 
       Query = "UPDATE table set item = '" & noOfItems & "' where username= '" & txtusername.Text & "'" 
       Command = New MySqlCommand(Query, connection) 
       Command.ExecuteNonQuery() 
       MessageBox.Show(username & "- The number of items you have is: " & noOfItems) 
      End If 
     Else 
      MsgBox("Unlucky, Incorrect item. Please see hints. Your score still remains the same") 
     End If 
     connection.close() 
    Catch ex As Exception 
     MessageBox.Show("Error") 
    End Try 
End Sub 
+0

嘿@mysta谢谢你的回复!但是我忘了提及,我已经在公共课程中初始化了这个项目和命令。 – karan

+0

我编辑我的答案。 – Mysta

+0

解决了出现的消息框(但现在不显示查询中递增的值) - p.s我真的很感谢帮助@mysta – karan