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?

Recommended Answers

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 …

Jump to Post

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.