ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1727
Number of posts: 3292

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Gridview not updating DB Posted by Fabio on 26 Feb 2010 at 9:04 AM
Hi all,
it's been a long long time I don't came here, but here I am again!

I'm sorry if this is (shurely) a stupid question, but I'm not able to solve a problem with an asp net 2.0/vb net code behind web application.
Here it is:

Event: "GridView1_RowUpdating"
After modifing values in "gridview1" control, i press "update" button, that obviously calls "gridview1_rowupdating" event.
All fine till here but... data values in DB (it's an access db) are not updated, they still remain the same as before.

Here below is the code, what I'm doing wrong?

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
 
 Dim strConnString As String = ConfigurationManager.ConnectionStrings("conn_oledb").ConnectionString
        Dim conn As New OleDb.OleDbConnection(strConnString)
        Dim objreader As OleDb.OleDbDataReader
        Dim command As New OleDb.OleDbCommand
        command.Connection = conn

        Dim f1 As Long
        Dim id As Integer

        f1 = DirectCast(GridView1.Rows(e.RowIndex).Cells(1).Controls(0), TextBox).Text
       id = Integer.Parse(e.RowIndex)
       
       'i valori id ed f1 fin qua vengoo correttamente assegnati

        e.Cancel = True
        conn.Open()
        command.CommandText = "UPDATE tabella SET f1= @f1 where id= @id"
        command.Parameters.AddWithValue("@f1", f1)
        command.Parameters.Addwithvalue("@id", id)
        command.ExecuteNonQuery()
        GridView1.EditIndex = -1


P.S.
Last but not least: sorry for my so bad english, hope you understand!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.