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 September 30th, 2003, 09:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default Updating an Access DB

I am able to enter text in the input boxes but when I click update, whatever I have entered goes away and it doesn't get updated.

Here is my update code:

Sub dgNews_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles dgNews.UpdateCommand
        Dim objCommand As OleDbCommand
        Dim strSQLQuery As String
        Dim txtTitle As TextBox
        Dim txtNews As TextBox
        Dim strTitle As String
        Dim strNews As String
        Dim intID As Integer


        strSQLQuery = "UPDATE [zNews] SET [news_title]=@Title, [the_news]=@News " _
         & "WHERE [znews].[theid]=@ID"

        objCommand = New OleDbCommand(strSQLQuery, objConn)

        txtTitle = e.Item.Cells(1).Controls(0)
        strTitle = txtTitle.Text
        objCommand.Parameters.Add(New OleDbParameter("@Title", OleDbType.VarChar, 49))
        objCommand.Parameters("@Title").Value = strTitle

        txtNews = e.Item.Cells(2).Controls(0)
        strNews = txtNews.Text
        objCommand.Parameters.Add(New OleDbParameter("@News", OleDbType.VarChar, 49))
        objCommand.Parameters("@News").Value = strNews

        intID = dgNews.DataKeys(e.Item.ItemIndex)
        objCommand.Parameters.Add("@ID", intID)

        objConn.Open()
        objCommand.ExecuteNonQuery()
        objConn.Close()
        dgNews.EditItemIndex = -1


        ShowDataGrid()
    End Sub

Any suggestions?
 
Old September 30th, 2003, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

The solution is this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            objConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
                            "data source=E:\Inetpub\wwwroot\news\news stories.mdb")
            ShowDataGrid()
        Else
            objConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
                            "data source=E:\Inetpub\wwwroot\news\news stories.mdb")
        End If
    End Sub

I had it reloading the datagrid with each page load. That made the dgNews_UpdateCommand sub update with the old information instead of grabbing the new information.





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with updating the db using servlet Behl_Neha Java Databases 1 December 24th, 2007 06:08 AM
I am an idiot....DB not updating w/o Agent? Raconteur SQL Server 2000 4 April 24th, 2007 11:30 AM
Updating an Access 200 db Gandalf_the_Grey Classic ASP Basics 3 June 27th, 2006 07:09 AM
Updating DB abbylee26 Classic ASP Databases 15 March 17th, 2004 06:21 AM
updating db with dataAdapter/dataTable problem mm1234 ADO.NET 0 November 19th, 2003 06:49 AM





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