0


I am trying to update a MySQL table in Visual Basic 2015 using the following code inside a button click but getting an error:

        Try
        stm = "UPDATE company SET CompanyName='" + TextBox4.Text + "';" 
        conn.Open()
        MessageBox.Show("Data Updated")
        While myReader.Read()
        End While 
        conn.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message.ToString())
    End Try

The error I get is Object Reference not set to an instance of an object. Any guidance would be appreciated.

Thanks.

  • Don't use string concatenation to build sql queries, use parameterized queries to prevent sql-injection. – Tim Schmelter Sep 20 '16 at 11:32
  • How is this an exact duplicate of http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – user3719039 Sep 20 '16 at 11:51
  • Because it asks how to fix the `NullReferenceException`. Use the suggestions in the accepted answer and you will find it out yourself. The debugger is your friend. – Tim Schmelter Sep 20 '16 at 11:52

0 Answers0