Protected Sub updatedata()

        Dim command As New MySqlCommand("UPDATE company_alert, company_financial SET company_alert.alert_value = (company_financial.receivable * 360 / company_financial.revenue)WHERE company_alert.alert_id='DSO' AND company_alert.stock_code = company_financial.stock_code AND company_alert.year_id = company_financial.year_id AND company_alert.period_id = company_financial.period_id", conn)

    End Sub
    Protected Sub insertdata()

        Dim strSQL As String
        strSQL = "INSERT INTO company_alert (stock_code, year_id, period_id,alert_id, alert_value) "
        strSQL = strSQL & "SELECT a.stock_code, a.year_id, a.period_id,alert_id,(a.receivable*360/a.revenue) AS dso1 "
        strSQL = strSQL & "FROM ref_alert_parameter, company_financial a "
        strSQL = strSQL & "WHERE alert_id='DSO' AND a.year_id BETWEEN '" & byear1 & "' AND '" & byear2 & "' AND a.period_id = '5'"

        cmd = New MySqlCommand(strSQL, conn)

        cmd.CommandTimeout = 0

    End Sub

How am i to do the checking in db that if stock_code already have in the company_alert it will go to insert..

See if you can select the key first.

You can check to see if certain data exists in db by using IF EXISTS(Condition) ELSE

IF EXISTS (SELECT * FROM company_alert WHERE stock_code = "your stock code")
 UPDATE company_alert, company_financial .