I'm very new to programming and was wondering why I am receiving a warning.
"Function Checkbox doesnt return a value on all code paths. A null reference exception could occur at runtime when the result is used"
I then want to execute this function through button.click event: CheckBox.ExecuteNonQuery()
Function CheckBox() As SqlCommand
Dim ConnString As String = "Data Source=08.4.4.56;Initial Catalog=" + txtPortal.Text + ";Persist Security Info=True;User ID=USER1;Password=" + TextBox1.Text
Using Con As New SqlConnection(ConnString)
Con.Open()
If cb18g.Checked Then
sql = "UPDATE ItemType SET IsActive = 1 WHERE ItemTypeCode = @ItemTypeCode"
Dim cmd As New SqlCommand(sql, Con)
cmd.Parameters.Add("@ItemTypeCode", SqlDbType.VarChar, 3)
cmd.Parameters("@ItemTypeCode").Value = "18G"
cmd.ExecuteNonQuery()
ElseIf cb35g.Checked Then
sql = "UPDATE ItemType SET IsActive = 1 WHERE ItemTypeCode = @ItemTypeCode"
Dim cmd As New SqlCommand(sql, Con)
cmd.Parameters.Add("@ItemTypeCode", SqlDbType.VarChar, 3)
cmd.Parameters("@ItemTypeCode").Value = "35G"
cmd.ExecuteNonQuery()
Else
MsgBox("DEFUALT ITEM ACTIVE")
End If
End Using
End Function