imslala 0 Newbie Poster

Hi there,

I need help regards to my sql statement. I am developing a system using vb.net but now i'm having trouble to insert all the data (where i bind using repeater control) into the sql statement. I didn't know how to declare the stockcode.Text, year.Text, quarter.Text and total1.text as what. could anyone please help me.


This is my insert code;

Protected Sub InsertData()

        ConnectDatabase()


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

        command.Parameters.AddWithValue("@stock_code", stockCode.Text)
        command.Parameters.AddWithValue("@year_id", year.Text)
        command.Parameters.AddWithValue("@period_id", quarter.Text)
        command.Parameters.AddWithValue("@alert_value", total1.Text)
        command.Parameters.AddWithValue("@created_by", HttpContext.Current.Session("userid"))
        command.Parameters.AddWithValue("@created_date", Format(Now(), "yyyy-MM-dd HH:mm"))

        command.ExecuteNonQuery()
        DisconnectDatabase()


    End Sub

Below are my repeater code;

Protected Sub repeaterQuarter_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles repeaterQuarter.ItemDataBound

        stockCodeheaderq.Text = " Stock Code "
        plcNameheaderq.Text = " PLC Name "
        boardheaderq.Text = " Board "
        sectorheaderq.Text = " Sector "
        subSectorheaderq.Text = " Sub Sector "
        yearheaderq.Text = " Year "
        periodheaderq.Text = " Quarter "
        totalq.Text = " DSO "

        '** Declare Session **'
        If Session("tempara1") = "" Then
            DSO = e.Item.DataItem("para1")
        Else
            DSO = 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 quarter As Label = CType(e.Item.FindControl("quarter"), Label)
        If Not IsNothing(quarter) Then
            quarter.Text = e.Item.DataItem("period_name").ToString
        Else
            'quarter.Text = "N/A"
        End If

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

        'If total1.Text >= e.Item.DataItem("tempara").ToString Then
        If total1.Text >= DSO Then
            total1.BackColor = Drawing.Color.Red
        End If

    End Sub
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.