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

G

ggoldab

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
 
S

Stan

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top