Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Gridview won't update after inserting new record to MS Accessdatabase using OLEDB

Reply
Thread Tools

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

 
 
ggoldab@gmail.com
Guest
Posts: n/a
 
      09-22-2008
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
 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      09-22-2008
On 22 Sep, 07:57, (E-Mail Removed) 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on inserting record from footer of a GridView: mmahal ASP .Net 0 12-12-2009 05:53 AM
Get DropDownList To Rebind On Inserting A Record In GridView Microsoft News Group ASP .Net 0 08-10-2006 08:41 PM
using dropdown box to display db record & update record Jimmy Tran ASP General 1 10-03-2003 04:20 PM
Error when trying to add an Access DB Record containing a Long Integer type field using OLEDB in ADO.Net Robert Hanson ASP .Net 4 07-22-2003 01:40 PM
Re: Error when trying to add an Access DB Record containing a Long Integer type field using OLEDB in ADO.Net Robert Hanson ASP .Net 1 07-22-2003 12:54 PM



Advertisments