0

Good Day,

I am have this error System.NullReferenceException:Object reference not set to an instance of an object. when i trigger the update button. I have a listview in my form 1 so i can add data which is working fine and accepting blank values so the user can add data in the future. but when i am trying to INSERT... DUPLICATE KEY ON UPDATE i am having this error.

 Dim cmd6 As New MySqlCommand(cs, conn2)
                With cmd6
                    .CommandText = "INSERT INTO workrecord (entryno, empid2, position, company, sdate, edate, yoservice, reason)" _
                     & "VALUES (@entryno, @empid2, @position, @company, @sdate, @edate, @yoservice, @reason)" _
                     & "ON DUPLICATE KEY UPDATE entryno = @entryno, empid2 = @empid2, position = @position, company = @company, sdate = @sdate, edate = @edate, yoservice = @yoservice, reason = @reason"
                    .Parameters.AddWithValue("@entryno", itm1.Text)
                    .Parameters.AddWithValue("@empid2", itm1.SubItems(1).Text)
                    .Parameters.AddWithValue("@position", itm1.SubItems(2).Text)
                    .Parameters.AddWithValue("@company", itm1.SubItems(3).Text)
                    .Parameters.AddWithValue("@sdate", itm1.SubItems(4).Text)
                    .Parameters.AddWithValue("@edate", itm1.SubItems(5).Text)
                    .Parameters.AddWithValue("@yoservice", itm1.SubItems(6).Text)
                    .Parameters.AddWithValue("@reason", itm1.SubItems(7).Text)
                    .ExecuteNonQuery()
                End With
dran1979
  • 3
  • 1
  • 1
    You are getting this Error because you are trying to call `.Text` in a SubItem that is Nothing probably. – G3nt_M3caj Aug 30 '20 at 16:27
  • Hi sir yes i figured it out, i have the same type of these procedure in another form, and my update button is centralized meaning updating all datas in 3 different forms so if i clicked the update button even if i am using the insert.. on duplicate key update...statement..the other form has no value so these error will pop.. anyway thank you for helping me out. – dran1979 Sep 02 '20 at 10:39

0 Answers0