Results 1 to 3 of 3

Thread: Please Help!!!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Australia
    Posts
    73

    Please Help!!!!!

    I am writing a guest book for a web page that I am developing at the moment. The guest book is kept in an access database.

    I can get the data out alright and display it, however the problem occurs when the user goes to add a comment.

    Everything works fine. The user puts all the info in and then clicks on the submit button. It seems that it works. But when the page refreshes the data is not there.

    I think there must be something wrong with the add function.

    Could some one please help me out as I am at the end of my witts.

    The code is below. Cheers,

    Public Function Add(ByVal Author As String, ByVal Email As String, _
    ByVal Homepage As String, ByVal State As String, ByVal Comment As String) As Boolean
    Dim sql As String = "INSERT INTO Comments (Author, Email, Homepage, State, Comment) "
    sql += "VALUES (@Author, @Email, @Homepage, @State, @Comment)"
    ' create a new OleDbCommand and set its params
    Dim myCmd As OleDbCommand = New OleDbCommand(sql, _Connection)
    myCmd.Parameters.Add(New OleDbParameter("@Author", OleDbType.VarChar, 50))
    myCmd.Parameters("@Author").Value = Author.Trim()
    myCmd.Parameters.Add(New OleDbParameter("@Email", OleDbType.VarChar, 50))
    myCmd.Parameters("@Email").Value = Email.Trim()
    myCmd.Parameters.Add(New OleDbParameter("@Homepage", OleDbType.VarChar, 100))
    myCmd.Parameters("@Homepage").Value = Homepage.Trim()
    myCmd.Parameters.Add(New OleDbParameter("@State", OleDbType.VarChar, 50))
    myCmd.Parameters("@State").Value = State.Trim()
    myCmd.Parameters.Add(New OleDbParameter("@Comment", OleDbType.VarChar))
    myCmd.Parameters("@Comment").Value = EncodeHTMLText(Comment.Trim())
    Add = True
    myCmd.Connection.Open()
    Try
    myCmd.ExecuteNonQuery()
    Catch e As OleDbException
    Add = False
    Finally
    myCmd.Connection.Close()
    End Try
    End Function
    Hugh Rees
    SERTEV Technologies
    (07) 3375 9806
    0410 585 754
    WWW.SERTEV.COM

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Have you tried using ? instead of @paramname:-

    Dim sql As String = "INSERT INTO Comments (Author, Email, Homepage, State, Comment) "
    sql &= "VALUES (?, ?, ?, ?, ?)"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Australia
    Posts
    73
    I gave up and re wrote the form using ADODB. My code is below. If any one has any ways to improve please tell me.

    Thankx for your help.....

    Dim rs As ADODB.Recordset
    rs = New ADODB.Recordset()
    rs.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
    rs.LockType = ADODB.LockTypeEnum.adLockOptimistic
    rs.Open("Comments", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\webspace\myweb.com\db\Guestbook.mdb;Persist Security Info=False;", , , ADODB.CommandTypeEnum.adCmdTable)
    rs.AddNew()
    rs.Fields(1).Value = Author.Text
    rs.Fields(2).Value = Email.Text
    rs.Fields(3).Value = Homepage.Text
    rs.Fields(4).Value = State.Text
    rs.Fields(5).Value = Comment.Text
    rs.Update()
    rs.Close()
    rs = Nothing
    Hugh Rees
    SERTEV Technologies
    (07) 3375 9806
    0410 585 754
    WWW.SERTEV.COM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width