0
Protected Sub updatedata()

        Dim strSQL As String
        strSQL = "UPDATE company_alert, company_financial"
        strSQL = strSQL & " company_alert.alert_value = (company_financial.receivable * 360 / company_financial.revenue)"
        strSQL = strSQL & "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"

        cmd = New MySqlCommand(strSQL, conn)
        cmd.ExecuteNonQuery()

    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.ExecuteNonQuery()

        cmd.CommandTimeout = 0


    End Sub

I insert data 1st next im gonna update the data..is it true or update then insert?

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by bluehangook629
0

How can you update date that isn't in the database? Insert then update is probably better, assuming you aren't updating the information you just inserted because that doesn't make much sense (you'd just insert correctly the first time right??).

In the posted code you have a mistake on line 4, you're missing a comma after company_financial.

0

update is to alter a value in your database and insert is to create new record in the database. I say insert if data doesnt exist and update if data already exists.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.