Hi all. i have a problem on my coding here. it should insert the new triggered alert into database but it does not work. please have a look and tell me which part i've done wrong. thank you :)

Protected Sub repeaterAlert_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles repeaterAlert.ItemDataBound
        Try

            stockCodeheader.Text = " Stock Code "
            plcNameheader.Text = " PLC Name "
            boardheader.Text = " Board "
            sectorheader.Text = " Sector "
            subSectorheader.Text = " Sub Sector "
            yearheader.Text = " Year "
            total.Text = " DSO "

            '** Declare Session **'
            If Session("tempara1") = "" Then
                DSO1 = Double.Parse(e.Item.DataItem("para1").ToString)
            Else
                DSO1 = Double.Parse(Session("tempara1"))
            End If
            '*********************'

            Dim stockCode As Label = CType(e.Item.FindControl("stockCode"), Label)
            If Not IsNothing(stockCode) Then
                stockCode.Text = e.Item.DataItem("stock_code").ToString
            End If

            Dim plcName As Label = CType(e.Item.FindControl("plcName"), Label)
            If Not IsNothing(plcName) Then
                plcName.Text = e.Item.DataItem("current_name").ToString
            Else
            End If

            Dim board As Label = CType(e.Item.FindControl("board"), Label)
            If Not IsNothing(board) Then
                board.Text = e.Item.DataItem("board_name").ToString
            Else
            End If

            Dim sector As Label = CType(e.Item.FindControl("sector"), Label)
            If Not IsNothing(sector) Then
                sector.Text = e.Item.DataItem("sector_name").ToString
            Else
            End If

            Dim subSector As Label = CType(e.Item.FindControl("subSector"), Label)
            If Not IsNothing(subSector) Then
                subSector.Text = e.Item.DataItem("sub_sector_name").ToString
            Else
            End If

            Dim year As Label = CType(e.Item.FindControl("year"), Label)
            If Not IsNothing(year) Then
                year.Text = e.Item.DataItem("year_id").ToString
            Else
            End If

            Dim total1 As Label = CType(e.Item.FindControl("total1"), Label)
            total1.Text = Double.Parse(e.Item.DataItem("dso").ToString)
            Dim compval As Double = total1.Text
            total1.Text = Math.Round(compval, 2)

            If total1.Text >= DSO1 Then
                total1.BackColor = Drawing.Color.Red

            ElseIf total1.Text = "" Then
                'total1.Text = "N/A"
            End If


            '** insert to fistdb **'

            ConnectDatabase()

            Dim command As New MySqlCommand("INSERT INTO company_alert (stock_code, year_id, alert_id, alert_value, created_by, created_date) VALUES (@stock_code, @year_id, @alert_id, @alert_value, @created_by, @created_date)", conn)

            command.Parameters.AddWithValue("@stock_code", CType(e.Item.FindControl("stockCode"), Label))
            command.Parameters.AddWithValue("@year_id", CType(e.Item.FindControl("year"), Label))
            command.Parameters.AddWithValue("@alert_id", ("DSO"))
            command.Parameters.AddWithValue("@alert_value", CType(e.Item.FindControl("total1"), Label))
            command.Parameters.AddWithValue("@created_by", HttpContext.Current.Session("userid"))
            command.Parameters.AddWithValue("@created_date", Format(Now(), "yyyy-MM-dd HH:mm"))

            command.ExecuteNonQuery()

            DisconnectDatabase()

        Catch ex As Exception

        End Try

    End Sub

Any error in catch block?

no error inside the catch block

ConnectDatabase() is working? ur pointing to correct DB? cpde looks good. should insert the record... check connections and and connection string.

command.Parameters.AddWithValue("@stock_code", CType(e.Item.FindControl("stockCode"), Label))

You try to insert a Label in to your database?
If not then change it to:
command.Parameters.AddWithValue("@stock_code", CType(e.Item.FindControl("stockCode"), Label).Text)

put all your code in try exception block and let us know what the error message is

Try
(your code)
Catch ex As SystemException
msgbox(ex.message)
Catch ex As SQLException
msgbox(ex.message)
END TRY
Be a part of the DaniWeb community

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