Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 2nd, 2004, 12:43 AM
Authorized User
Join Date: Sep 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cjcd
Default HELP!!! Datalist Editing

Please help me, I've done everything there is to try and fix the error
and I don't know what else to do. The error is SYNTAX ERROR IN UPDATE

Here's the .aspx

<%@ Page Language="vb" Src="approve.vb" Inherits="Approve" debug="true"
trace="true" %>

<title>Dot.Net Guestbook - Approve Comments</title>
<style rel="stylesheet">
  .name { font-size: 10px; font-family: Arial, Helvetica, sans-serif; }
  .comment { font-size: 12px; font-family: Arial, Helvetica,
sans-serif; }
  .customersHead { font: bold 8pt Verdana, Arial, sans-serif;
                  background-color:#4A3C8C; color:white; }
  a { text-decoration:underline; }
  a:hover { text-decoration:underline; color:#4A3C8C; }
  .button { font-size: 9px; font-family: Arial, Helvetica, sans-serif;

<form runat="server" id="form1">

<asp:Datalist id="dtlComments"

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <td width="160" class="name"><%#
DataBinder.Eval(Container.DataItem, "name") %></td>
    <td width="400" class="comment"><%#
DataBinder.Eval(Container.DataItem, "comment") %></td>
    <td width="100"><asp:button id="btnEdit" Runat="server"
class="button" CommandName="edit" Text="Edit Comment" /></td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

    <td>Name: <asp:TextBox id="txtname" Runat="server" Columns="20"
Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' /></td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <td><table width="100%" border="0" cellspacing="0"
                <td>ID: <asp:label id="lblCommentid" runat="server"
text='<%# DataBinder.Eval(Container.DataItem, "commentID") %>' /></td>
                <td>Approved: <asp:TextBox id="txtapprove"
Runat="server" Columns="2" Text='<%# DataBinder.Eval(Container.DataItem,
"approved") %>' />1 = Y / 0 = N</td>
          <td>Date: <asp:TextBox id="txtdate" Runat="server"
Columns="30" Text='<%# DataBinder.Eval(Container.DataItem, "date") %>' /></td>
          <td>City: <asp:TextBox id="txtcity" Runat="server"
Columns="30" Text='<%# DataBinder.Eval(Container.DataItem, "city") %>' /></td>
          <td>Country: <asp:TextBox id="txtcountry" Runat="server"
Columns="30" Text='<%# DataBinder.Eval(Container.DataItem, "country") %>'
          <td>Email: <asp:TextBox id="txtemail" Runat="server"
Columns="30" Text='<%# DataBinder.Eval(Container.DataItem, "email") %>' /></td>
          <td>URL: <asp:TextBox id="txturl" Runat="server" Columns="30"
Text='<%# DataBinder.Eval(Container.DataItem, "url") %>' /></td>
    <td>Comments: <asp:TextBox textmode="multiline" id="txtcomment"
Runat="server" Columns="30" Rows="4" Text='<%#
DataBinder.Eval(Container.DataItem, "comment") %>' /></td>
    <td align="center">
    <asp:Button id="btnUpdate" Runat="server" CommandName="update"
Text="Update" /><asp:Button id="btnCancel" Runat="server" CommandName="cancel"
Text="Cancel" />
<br />
<table width="560" border="0" cellspacing="0" cellpadding="0"
style="filter:progid:DXImageTransform.Microsoft.Gr adient(GradientType=1, StartColorStr='#FF99CCFF', EndColorStr='#FFFFCC00');
padding-left: 5px;">
        <asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="default.aspx" class="comment">View Comments</asp:HyperLink>


Here's the .vb file

Imports System
Imports System.Data
Imports System.Data.Oledb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration

Public Class Approve : Inherits Page

  Private strConn As String =
  Public dtlComments As DataList

  Public Sub Page_Load(sender as Object, e as EventArgs)

    If Not IsPostBack Then
    End If

  End Sub

  Private Sub BindTheData()

    Dim objConn as new OledbConnection(strConn)
    Dim strSQL as String
    strSQL = "SELECT * FROM Comments WHERE Approved='0'"
    Dim sda as new OledbDataAdapter(strSQL, objConn)
    Dim ds as new DataSet()
    dtlComments.DataSource = ds.Tables("Comments").DefaultView

  End Sub

  Public Sub dtlComments_Edit(sender as Object, e as

    dtlComments.EditItemIndex = e.Item.ItemIndex

  End Sub

  Public Sub dtlComments_Cancel(sender as Object, e as

    dtlComments.EditItemIndex = -1

  End Sub

  Public Sub dtlComments_Update(sender As Object, e As

    Dim strName, strApprove, strDate, strCity As String
    Dim strCountry, strEmail, strURL, strComment, strCommentID As

    strName = CType(e.Item.FindControl("txtName"), TextBox).Text
    strApprove = CType(e.Item.FindControl("txtApprove"), TextBox).Text
    strDate = CType(e.Item.FindControl("txtdate"), TextBox).Text
    strCity = CType(e.Item.FindControl("txtcity"), TextBox).Text
    strCountry = CType(e.Item.FindControl("txtcountry"),TextBox).Te xt
    strEmail = CType(e.Item.FindControl("txtemail"), TextBox).Text
    strURL = CType(e.Item.FindControl("txturl"),TextBox).Text
    strComment = CType(e.Item.FindControl("txtcomment"),TextBox).Te xt
    strCommentID = CType(e.Item.FindControl("lblCommentID"),

    Dim strSQL As String
    strSQL = "Update Comments " & _
    "Set [Name] = @Name," & _
    "[eMail] = @Email," & _
    "[URL] = @URL, " & _
    "[City] = @City, " & _
    "[Country] = @Country, " & _
    "[Date] = @Date, " & _
    "[Comment] = @Comment, " & _
    "[Approved] = @Approved, " & _
    "WHERE CommentID = @CommentID"

    Dim objConn As New OledbConnection(strConn)
    Dim Cmd As New OledbCommand(strSQL, objConn)

    With Cmd.Parameters
        .Add(New OleDbParameter("@Name", strName))
        .Add(New OleDbParameter("@Email", strEmail))
        .Add(New OleDbParameter("@Url", strURL))
        .Add(New OleDbParameter("@City", strCity))
        .Add(New OleDbParameter("@Country", strCountry))
        .Add(New OleDbParameter("@Date", strDate))
        .Add(New OleDbParameter("@Comment", strComment))
        .Add(New OleDbParameter("@Approved", strApprove))
        .Add(New OledbParameter("@CommentID", strCommentID))
    End With


    dtlComments.EditItemIndex = -1

  End Sub

  End Class

Thank you so much for your help.

Old April 3rd, 2004, 08:17 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Whenever you get a database error, double double check check your query!
    "[Approved] = @Approved, " & _
    "WHERE CommentID = @CommentID"

Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
Editing File Hind Java Basics 2 June 14th, 2006 07:04 PM
Need Help A Editing String! Little Shell VB.NET 2002/2003 Basics 2 June 4th, 2005 03:05 AM
Help on Image Editing Raghavendra_Mudugal VB How-To 1 March 22nd, 2005 12:06 PM
Datalist editing not working cjcd ASP.NET 1.0 and 1.1 Basics 4 April 3rd, 2004 07:28 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.