Wrox Programmer Forums
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 August 11th, 2005, 09:35 AM
Authorized User
Join Date: Mar 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit records problems

Hi guys

When ever I attempt to run my EditPub.aspx page, it only runs the html code which is displayed at the top of the page. I can't even check the code for errors. Can anyone help?

<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

        Sub Page_Load(sender As Object, e As EventArgs)
            If Not Page.IsPostBack
            End If
        End Sub

        Sub BindData()

            '1. Start the Connection String

            Const conPub As String = ( _
                  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                      "Data Source=c:\Inetpub\wwwroot\Learnasp\biblio2.mdb")

            Dim objConn As New OleDbConnection(conPub)
            objConn.Open() 'You must open the db connection before populating the datareader

            '2 Build the SQL query 

            Const strSQL As String =  "SELECT * FROM Publishers ORDER BY PubID DESC"
            Dim objCmd As New OleDbCommand(strSQL, objConn) 

            '3 Create/Populate the DataReader

            Dim objDR As OleDbDataReader
            objDR = objCmd.ExecuteReader()

            dgPub.DataSource = objDR
        End Sub

        Sub dgPub_Edit(sender As Object, e As DataGridCommandEventArgs)
            dgPub.EditItemIndex = e.Item.ItemIndex
        End Sub

        Sub dgPub_Cancel(sender As Object, e As DataGridCommandEventArgs)
            dgPub.EditItemIndex = -1
        End Sub

        Sub dgPub_Update(sender As Object, e As DataGridCommandEventArgs)
            ' Read in the values of the update row
            Dim iPubID As Integer = e.Item.Cells(1).Text
            Dim strPubName As String = Ctype(e.Item.Cells(2).Controls(0), Textbox).Text
            Dim strCompanyName As String = Ctype(e.Item.Cells(3).Controls(0), Textbox).Text
            Dim strAddress As String = Ctype(e.Item.Cells(4).Controls(0), Textbox).Text
            Dim strCity As String = Ctype(e.Item.Cells(5).Controls(0), Textbox).Text
            Dim strState As String = Ctype(e.Item.Cells(6).Controls(0), Textbox).Text
            Dim strZip As String = Ctype(e.Item.Cells(7).Controls(0), Textbox).Text
            Dim strTelephone As String = Ctype(e.Item.Cells(8).Controls(0), Textbox).Text
            Dim strFax As String = Ctype(e.Item.Cells(9).Controls(0), Textbox).Text
            Dim strComments As String = Ctype(e.Item.Cells(10).Controls(0), Textbox).Text

        ' Construct the SQL statement using Parameters

            Dim strSQL As String = "UPDATE [Publishers] SET [PubName] = @PubName, " & _
                                   "[CompanyName] = @CompanyName, [Address] = @Address, " & _
                                   "[City] = @City, [State] = @State, [Zip] = @Zip, " & _
                                   "[Telephone] = @Telephone, [Fax] = @Fax, [Comments] = @Comments, " & _
                                   "WHERE [PubID] = @PubID"

            '1 Create an instance of the Connection

            Const conPub As String = ( _
                  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                      "Data Source=c:\Inetpub\wwwroot\Learnasp\biblio2.mdb")

            Dim objConn As New OleDbConnection(conPub)

            Dim myCommand As OleDbCommand = new OleDbCommand(strSQL, objConn)
            myCommand.CommandType = CommandType.Text

            ' Add Paramters to the SQL query

            Dim parameterPubName as OleDbParameter = new OleDbParameter("@PubName", OleDbType.VarWChar, 15)
            parameterPubName.Value = strPubName

            Dim parameterCompanyName as OleDbParameter = new OleDbParameter("@CompanyName", OleDbType.VarWChar, 20)
            parameterCompanyName.Value = strCompanyName

            Dim parameterAddress as OleDbParameter = new OleDbParameter("@Address", OleDbType.VarWChar, 70)
            parameterAddress.Value = strAddress

            Dim parameterCity as OleDbParameter = new OleDbParameter("@City", OleDbType.VarWChar, 20)
            parameterCity.Value = strCity

            Dim parameterState as OleDbParameter = new OleDbParameter("@State", OleDbType.VarWChar, 20)
            parameterState.Value = strState

            Dim parameterZip as OleDbParameter = new OleDbParameter("@Zip", OleDbType.VarWChar, 10)
            parameterZip.Value = strZip

            Dim parameterTelephone as OleDbParameter = new OleDbParameter("@Telephone", OleDbType.VarWChar, 20)
            parameterTelephone.Value = strTelephone

            Dim parameterFax as OleDbParameter = new OleDbParameter("@Fax", OleDbType.VarWChar, 20)
            parameterFax.Value = strFax

            Dim parameterComments as OleDbParameter = new OleDbParameter("@Comments", OleDbType.VarWChar, 20)
            parameterState.Value = strComments

            myCommand.ExecuteNonQuery() 'EXECUTE the UPDATE QUERY


            'Finally set the EditItemIndex to -1 and rebind the DataGrid

            dgPub.EditItemIndex = -1
        End Sub
    <title>Updating a database with .Net</title>
<body text="#000000" bgcolor="#ffffff" font face ="Verdana">
    <h2 font face ="Verdana">Changing Information about the Publishers
<form runat="server">

<asp:DataGrid id="dgPub" 



        <asp:EditCommandColumn EditText=" Edit " ButtonType="PushButton"
                UpdateText="Update" CancelText="Cancel" />
        <asp:BoundColumn DataField="PubID" HeaderText="Publishers ID" ReadOnly="True" />
        <asp:BoundColumn DataField="PubName" HeaderText="Publisher" />
        <asp:BoundColumn DataField="CompanyName" HeaderText="Company Name" />
        <asp:BoundColumn DataField="Address" HeaderText="Address" />
        <asp:BoundColumn DataField="City" HeaderText="City" />
        <asp:BoundColumn DataField="State" HeaderText="State" />
        <asp:BoundColumn DataField="Zip" HeaderText="Zip" />
        <asp:BoundColumn DataField="Telephone" HeaderText="Telephone" />
        <asp:BoundColumn DataField="Fax" HeaderText="Fax" />
        <asp:BoundColumn DataField="Comments" HeaderText="Comments" />

Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit or Delete records tsimsha Classic ASP Basics 6 October 30th, 2004 03:26 AM
how to know who edit or add records? drachx General .NET 1 October 13th, 2004 05:36 AM
how to know who edit add records? drachx SQL Server 2000 9 October 13th, 2004 04:28 AM
How to add edit records in .dbf file cbpanchal VB Databases Basics 1 July 7th, 2004 11:14 PM
How to add edit records in .dbf file cbpanchal VB How-To 2 June 25th, 2004 01:41 AM

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