Help, adding update button to StringBuilder made table

nakins

New member
Joined
Aug 21, 2008
Messages
4
Programming Experience
1-3
Hi,

This is probably the old way of doing things, but I'm doing a query to get the "unapproved" messages from a message table. I loop through a MysqlDataReader to build a table of unapproved messages. I added a standard html input button via the string builder for each message that has the row ID of the message. The html source for the button looks like:
<input type='submit' name='button1' value='Approve' id='4' OnClick='approveit(4)' />

However, this isn't working like I thought it would for the update function:
Public Sub approveit(ByVal e As EventArgs)

I know I'm probably way off here. Can someone point me in the right direction?

Thanks

VB.NET:
[COLOR="Blue"]Imports System.Data
Imports MySql.Data.MySqlClient
Partial Class Message_admin_approve
    Inherits System.Web.UI.Page
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            Dim conn As New MySqlConnection
            Dim objCommand As New MySqlCommand
            Dim objDataReader As MySqlDataReader
            Dim myConnString As String
            myConnString = "server=localhost; user id=user; password=password; database=mydb; pooling=false;"

            Dim strSQLQuery As String
            Dim sBld As New System.Text.StringBuilder()

            conn.ConnectionString = myConnString

            objCommand.Parameters.Add("?search", DateTime.Today)
            strSQLQuery = "SELECT * " _
             & "FROM brmessages " _
             & "WHERE (entrydate = ?search) AND (approved = 'no') "
            Try
                conn.Open()

                Try
                    objCommand.Connection = conn
                    objCommand.CommandText = strSQLQuery

                    objDataReader = objCommand.ExecuteReader


                    sBld.Append("<table width=100% border=1>")
                    Dim c As Integer
                    c = 1
                    Do While objDataReader.Read
                        sBld.Append("<tr><td width=100px><span style='color:#000000; font-size:15px; font-weight:bold'>")
                        sBld.Append(objDataReader("entrytime"))
                        sBld.Append("</td><td><span style='color:#084979; font-size:15px; font-weight:bold'>")
                        sBld.Append(objDataReader("message"))
                        sBld.Append("</span></td><td width=80px>")
                        sBld.Append("<input type='submit' name='button1' value='Approve' id='")
                        sBld.Append(c)
                        sBld.Append("' OnClick='approveit(")
                        sBld.Append(objDataReader("id"))
                        sBld.Append(")' />")
                        sBld.Append("</td></tr><tr>")
                        c = c + 1

                    Loop
                    sBld.Append("</table><br />")
                    sBld.Append("<hr><br>")
                    Label1.Text = sBld.ToString


                Catch myerror As MySqlException
                    MsgBox("There was an error reading from the database: " & myerror.Message)

                End Try

            Finally
                If conn.State <> ConnectionState.Closed Then conn.Close()
            End Try
        End If
    End Sub
    Public Sub approveit(ByVal e As EventArgs)
        Dim modConnection As MySqlConnection
        Dim modCommand As MySqlCommand

        Dim modSQLQuery As String

        modConnection = New MySqlConnection(""server=localhost; user id=user; password=password; database=mydb; pooling=false;")
        modSQLQuery = "UPDATE brmessages SET " _
                    & "approved = ?approve " _
                    & "WHERE id = ?eyedee"
        modCommand = New MySqlCommand(modSQLQuery, modConnection)

        modCommand.Parameters.Add("?eyedee", e)
        modCommand.Parameters.Add("?approve", "yes")

        modConnection.Open()
        Try
            modCommand.ExecuteNonQuery()
            'Message.Text = "<b>Record Updated</b><br>You may now search or select another record to update, or quit"
            'Message.Style("color") = "black"
        Catch ex As MySqlException
            'Message.Text = "ERROR: Could not update record"
            'Message.Style("color") = "red"
        End Try

        modConnection.Close()


    End Sub
End Class[/COLOR]
 
Back
Top