Gridview won't update after inserting new record to MS Accessdatabase using OLEDB

Discussion in 'ASP .Net Web Controls' started by ggoldab@gmail.com, Sep 22, 2008.

  1. Guest

    Hi,

    Here is my code on a button click in the EmptyDataTemplate of a
    Gridview. It saves the record to the database does not appear in the
    gridview after the calling the databind method.

    Any ideas ?

    Below is my code


    Protected Sub lnkSaveEmpty_Click(ByVal sender As Object, ByVal e
    As System.EventArgs)
    'save empty data
    'retriev the description
    Dim lnkSaveEmpty As LinkButton = sender
    Dim row As GridViewRow =
    DirectCast(lnkSaveEmpty.NamingContainer, GridViewRow)
    Dim dpItemNo_Empty As DropDownList =
    CType(row.FindControl("dpItemNo_Empty"), DropDownList)

    Dim strSQL As String, cmd As OleDbCommand, dr As
    OleDbDataReader
    Dim objConnection As OleDbConnection
    objConnection = New
    OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" &
    Server.MapPath("~\app_data\print_manager.mdb"))
    objConnection.Open() 'open the connection
    'strSQL = "Update tbl_job_details SET job_id = " &
    FormView1.DataKey(0) & ", card_id= " & dpItemNo_Empty.SelectedValue &
    ",qty=300 "
    strSQL = "Insert INTO tbl_job_details (job_id,card_id,qty)
    VALUES ( " & FormView1.DataKey(0) & "," & dpItemNo_Empty.SelectedValue
    & ",300)"
    cmd = New OleDbCommand(strSQL, objConnection)
    cmd.ExecuteNonQuery()
    GridView1.DataBind()

    End Sub


    Thanks

    Geoff
    , Sep 22, 2008
    #1
    1. Advertising

  2. Stan Guest

    On 22 Sep, 07:57, wrote:
    > Hi,
    >
    > Here is my code on a button click in the EmptyDataTemplate of a
    > Gridview. It saves the record to the database does not appear in the
    > gridview after the calling the databind method.
    >
    > Any ideas ?
    >
    > Below is my code
    >
    >     Protected Sub lnkSaveEmpty_Click(ByVal sender As Object, ByVal e
    > As System.EventArgs)
    >         'save empty data
    >         'retriev the description
    >         Dim lnkSaveEmpty As LinkButton = sender
    >         Dim row As GridViewRow =
    > DirectCast(lnkSaveEmpty.NamingContainer, GridViewRow)
    >         Dim dpItemNo_Empty As DropDownList =
    > CType(row.FindControl("dpItemNo_Empty"), DropDownList)
    >
    >         Dim strSQL As String, cmd As OleDbCommand, dr As
    > OleDbDataReader
    >         Dim objConnection As OleDbConnection
    >         objConnection = New
    > OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" &
    > Server.MapPath("~\app_data\print_manager.mdb"))
    >         objConnection.Open()   'open the connection
    >         'strSQL = "Update tbl_job_details SET job_id =  " &
    > FormView1.DataKey(0) & ", card_id= " & dpItemNo_Empty.SelectedValue &
    > ",qty=300  "
    >         strSQL = "Insert INTO tbl_job_details (job_id,card_id,qty)
    > VALUES ( " & FormView1.DataKey(0) & "," & dpItemNo_Empty.SelectedValue
    > & ",300)"
    >         cmd = New OleDbCommand(strSQL, objConnection)
    >         cmd.ExecuteNonQuery()
    >         GridView1.DataBind()
    >
    >     End Sub
    >
    > Thanks
    >
    > Geoff


    Hi Geoff

    Your code to save the record is obviously working OK but there is no
    indication of how your GridView is linked to the Database table. Are
    you using and AccessDataSource?
    Stan, Sep 23, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Hanson
    Replies:
    4
    Views:
    558
    Tu-Thach
    Jul 22, 2003
  2. Robert Hanson
    Replies:
    1
    Views:
    337
    Robert V. Hanson
    Jul 22, 2003
  3. Microsoft News Group
    Replies:
    0
    Views:
    410
    Microsoft News Group
    Aug 10, 2006
  4. mmahal
    Replies:
    0
    Views:
    397
    mmahal
    Dec 12, 2009
  5. Jimmy Tran
    Replies:
    1
    Views:
    226
    Dan Brussee
    Oct 3, 2003
Loading...

Share This Page