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
STATEMENT.

Here's the .aspx

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

<html>
<Head>
<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;
}
</style>
</HEAD>
<body>

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

<asp:Datalist id="dtlComments"
            runat="server"
            width="560"
            borderWidth="1"
            HeaderStyle-CssClass="customersHead"
            AlternatingItemStyle-BackColor="#99CCFF"
            Font-Size="10"
            Align="center"
            OnEditCommand="dtlComments_Edit"
            OnUpdateCommand="dtlComments_Update"
            OnCancelCommand="dtlComments_Cancel">

    <itemTemplate>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <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>
  </tr>
</table>
    </itemTemplate>
<EditItemTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>
    <td>Name: <asp:TextBox id="txtname" Runat="server" Columns="20"
Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' /></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="100%" border="0" cellspacing="0"
cellpadding="0">
              <tr>
                <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>
              </tr>
            </table></td>
          <td>Date: <asp:TextBox id="txtdate" Runat="server"
Columns="30" Text='<%# DataBinder.Eval(Container.DataItem, "date") %>' /></td>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <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>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td>Comments: <asp:TextBox textmode="multiline" id="txtcomment"
Runat="server" Columns="30" Rows="4" Text='<%#
DataBinder.Eval(Container.DataItem, "comment") %>' /></td>
  </tr>
  <tr>
    <td align="center">
    <asp:Button id="btnUpdate" Runat="server" CommandName="update"
Text="Update" /><asp:Button id="btnCancel" Runat="server" CommandName="cancel"
Text="Cancel" />
    </td>
    </tr>
</table>
</EditItemTemplate>
</asp:DataList>
<br />
<table width="560" border="0" cellspacing="0" cellpadding="0"
align="center"
style="filter:progid:DXImageTransform.Microsoft.Gr adient(GradientType=1, StartColorStr='#FF99CCFF', EndColorStr='#FFFFCC00');
padding-left: 5px;">
        <tr>
          <td>
        <asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="default.aspx" class="comment">View Comments</asp:HyperLink>
        </td>
        </tr>
        </table>
</form>

</body>
</html>
</code>

Here's the .vb file

<code>
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 =
ConfigurationSettings.AppSettings("myDSN")
  Public dtlComments As DataList

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

    If Not IsPostBack Then
      BindTheData()
    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()
    sda.Fill(ds,"Comments")
    dtlComments.DataSource = ds.Tables("Comments").DefaultView
    dtlComments.DataBind()

  End Sub

  Public Sub dtlComments_Edit(sender as Object, e as
DataListCommandEventArgs)

    dtlComments.EditItemIndex = e.Item.ItemIndex
    BindTheData()

  End Sub

  Public Sub dtlComments_Cancel(sender as Object, e as
DataListCommandEventArgs)

    dtlComments.EditItemIndex = -1
    BindTheData()

  End Sub

  Public Sub dtlComments_Update(sender As Object, e As
DataListCommandEventArgs)

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

    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"),
Label).Text

    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

    objConn.Open()
    cmd.ExecuteNonQuery()
    objConn.Close()

    dtlComments.EditItemIndex = -1
    BindTheData()

  End Sub




  End Class
</code>

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
Default

Whenever you get a database error, double double check check your query!
Code:
    "[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.