Hello,
I've been dealing with a NullException problem since yesterday. where I try to add values to my database accordingly to my query, but I keep getting this error:
"The object reference was not defined as an instance of an object"
What I have tried:
If CheckBox1.Checked = True Then
Try
con.ConnectionString = "The connection is good! I've used it on select statements and it works fine!"
Catch ex As Exception
End Try
Dim da As New MySqlDataAdapter()
Dim dt As New DataTable()
dt.Clear()
Dim cmd As New MySqlCommand("INSERT INTO D8_ALERTAQUALIDADE(CLIENTE, PROJETO, REFERENCIA, DESCRICAO, DATA_ENTRADA, DURACAO, DATA_SAIDA, FOTO1_OK, FOTO2_OK, FOTO3_OK, FOTO4_OK, FOTO1_NOK, FOTO2_NOK, FOTO3_NOK, FOTO4_NOK) VALUES(@D1,@D2,@D3,@D4,@D5,@D6,@D7,@D8,@D9,@D10,@D11,@D12,@D13,@D14,@D15)", con)
cmd.Parameters.AddWithValue("@d1", cmbCliente.SelectedValue)
cmd.Parameters.AddWithValue("@d2", cmbProjeto.SelectedValue)
cmd.Parameters.AddWithValue("@d3", cmbReferencia.SelectedValue)
cmd.Parameters.AddWithValue("@d4", TextBox1.Text)
cmd.Parameters.AddWithValue("@d5", dtpEntrada.Value.ToString("yyyy-mm-dd"))
cmd.Parameters.AddWithValue("@d6", cmbMeses.SelectedItem)
cmd.Parameters.AddWithValue("@d7", dtpDataSaida.Value.ToString("yyyy-mm-dd"))
cmd.Parameters.AddWithValue("@d8", PictureBox1.Image)
cmd.Parameters.AddWithValue("@d9", PictureBox2.Image)
cmd.Parameters.AddWithValue("@d10", PictureBox3.Image)
cmd.Parameters.AddWithValue("@d11", PictureBox4.Image)
cmd.Parameters.AddWithValue("@d12", PictureBox5.Image)
cmd.Parameters.AddWithValue("@d13", PictureBox6.Image)
cmd.Parameters.AddWithValue("@d14", PictureBox7.Image)
cmd.Parameters.AddWithValue("@d15", PictureBox8.Image)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
da.Fill(dt)
ElseIf CheckBox1.Checked = False Then
Try
con.ConnectionString ="The connection is good! I've used it on select statements"
Catch ex As Exception
End Try
Dim da As New MySqlDataAdapter()
Dim dt As New DataTable()
Dim cmd As New MySqlCommand("INSERT INTO D8_ALERTAQUALIDADE(CLIENTE, PROJETO, REFERENCIA, DESCRICAO, DATA_ENTRADA, DURACAO, DATA_SAIDA, FOTO1_OK, FOTO2_OK, FOTO3_OK, FOTO4_OK, FOTO1_NOK, FOTO2_NOK, FOTO3_NOK, FOTO4_NOK) VALUES(@D1,@D2,@D3,@D4,@D5,@D6,@D7,@D8,@D9,@D10,@D11,@D12,@D13,@D14,@D15)", con)
cmd.Parameters.AddWithValue("@d1", cmbCliente.SelectedValue)
cmd.Parameters.AddWithValue("@d2", cmbProjeto.SelectedValue)
cmd.Parameters.AddWithValue("@d3", cmbReferencia.SelectedValue)
cmd.Parameters.AddWithValue("@d4", TextBox1.Text)
cmd.Parameters.AddWithValue("@d5", dtpEntrada.Value.ToString("yyyy-mm-dd"))
cmd.Parameters.AddWithValue("@d6", cmbUmMes.SelectedItem)
cmd.Parameters.AddWithValue("@d7", dtpDataSaida.Value.ToString("yyyy-MM-dd"))
cmd.Parameters.AddWithValue("@d8", PictureBox1.Image)
cmd.Parameters.AddWithValue("@d9", PictureBox2.Image)
cmd.Parameters.AddWithValue("@d10", PictureBox3.Image)
cmd.Parameters.AddWithValue("@d11", PictureBox4.Image)
cmd.Parameters.AddWithValue("@d12", PictureBox5.Image)
cmd.Parameters.AddWithValue("@d13", PictureBox6.Image)
cmd.Parameters.AddWithValue("@d14", PictureBox7.Image)
cmd.Parameters.AddWithValue("@d15", PictureBox8.Image)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
da.Fill(dt)
End If