473,836 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Completely unable to update an access db from a datagrid

People, I am at my wit's end.

I am using the exact code from
http://aspnet.4guysfromrolla.com/articles/071002-1.aspx

And yet, the code does not manage to update the database. When I go to
update my database, I am able to get the form fields, and I am able to
replace the data, but when I go "update", the old data remains.

I have done everything correct, including this:
http://datawebcontrols.com/faqs/Edit...NotSaved.shtml
And yet the db will still not update.

Below is a copy of my code:
<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="Syst em.Data" %>
<% @Import Namespace="Syst em.Data.OleDb" %>
<% @Import Namespace="Syst em.Configuratio n" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="U ser-Agent"%>
<%@ Register TagPrefix="METZ " TagName="Meta" Src="/ssi/meta.ascx" %>
<%@ Register TagPrefix="METZ " TagName="Head" Src="/ssi/head.ascx" %>
<%@ Register TagPrefix="METZ " TagName="Foot" Src="/ssi/foot.ascx" %>
<METZ:Meta Id="ctlMeta" Runat="Server" />
<METZ:Head Id="ctlHead" Runat="Server" />
<script language="vb" runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
Dim myCmd as New OleDbCommand("S ELECT * FROM tblCarLinks", myConn)
myConn.Open()
dgCarLinks.Data Source =
myCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection)
dgCarLinks.Data Bind()
myConn.Close() 'Close the connection
End Sub

Sub dgCarLinks_Edit (sender As Object, e As DataGridCommand EventArgs)
dgCarLinks.Edit ItemIndex = e.Item.ItemInde x
BindData()
End Sub

Sub dgCarLinks_Upda te(sender As Object, e As DataGridCommand EventArgs)
'Read in the values of the updated row
Dim iID as Integer = e.Item.Cells(0) .Text
Dim strName as String = CType(e.Item.Ce lls(1).Controls (0),
TextBox).Text
Dim strURL as String = CType(e.Item.Ce lls(2).Controls (0), TextBox).Text
'Construct the SQL statement using Parameters
Dim strSQL as String = "UPDATE [tblCarLinks] SET
[CarLinksName]=@Name, [CarLinksURL]=@URL WHERE [ID]=@ID"

Dim objConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
objConn.Open()

Dim myCommand as OleDbCommand = new OleDbCommand(st rSQL, objConn)
' myCommand.Comma ndType = CommandType.Tex t

' Add Parameters to the SQL query
Dim parameterID as OleDbParameter = new OleDbParameter( "@ID",
OleDbType.Integ er)
parameterID.Val ue = iID
myCommand.Param eters.Add(param eterID)

Dim parameterName as OleDbParameter = new OleDbParameter( "@Name",
OleDbType.VarWC har)
parameterName.V alue = strName
myCommand.Param eters.Add(param eterName)

Dim parameterURL as OleDbParameter = new OleDbParameter( "@URL",
OleDbType.VarWC har)
parameterURL.Va lue = strURL
myCommand.Param eters.Add(param eterURL)

myCommand.Execu teNonQuery() 'Execute the UPDATE query

objConn.Close() 'Close the connection
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgCarLinks.Edit ItemIndex = -1
BindData()
End Sub
Sub dgCarLinks_Canc el(sender As Object, e As DataGridCommand EventArgs)
dgCarLinks.Edit ItemIndex = -1
BindData()
End Sub
</script>
<div id="content">
<h2>Cool Car Links</h2>
<form runat="server">
<asp:datagrid id="dgCarLinks " runat="server"
showheader="tru e"
autogeneratecol umns="False"
edititemstyle-backcolor="#ffc ccc"
oneditcommand=" dgCarLinks_Edit "
onupdatecommand ="dgCarLinks_Up date"
oncancelcommand ="dgCarLinks_Ca ncel"
cellpadding="10 "
width="100%">
<HeaderStyle backcolor="#000 000" forecolor="#fff fff" font-bold="true"
horizontalalign ="center" />
<ItemStyle backcolor="#fff fff" forecolor="#000 000" />
<AlternatingIte mStyle backcolor="#ccc ccc" />
<Columns>
<asp:BoundColum n DataField="ID" HeaderText="ID" ReadOnly="true" />
<asp:BoundColum n DataField="CarL inksName" HeaderText="Sit e Name" />
<asp:BoundColum n DataField="CarL inksURL" HeaderText="Sit e URL" />
<asp:EditComman dColumn EditText="Edit" ButtonType="Pus hButton"
UpdateText="Upd ate" CancelText="Can cel" />
</Columns>
</asp:datagrid>
</form>
</div>
<METZ:Foot Id="ctlFoot" Runat="Server" />

I hope that someone with sharper eyes than me can figure this monster out.

....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #1
4 1673
are you sure that iID parameter value is OK?
Peter
Dim strSQL as String = "UPDATE [tblCarLinks] SET [CarLinksName]=@Name,
[CarLinksURL]=@URL WHERE [ID]=@ID"

Nov 19 '05 #2
Rogas69 wrote:
are you sure that iID parameter value is OK?
Peter
Dim strSQL as String = "UPDATE [tblCarLinks] SET [CarLinksName]=@Name,
[CarLinksURL]=@URL WHERE [ID]=@ID"

Nope. That wasn't the problem (just changed both, no change). Besides,
iID was the Integer. @ID was the parameter.

Thanks anyways
....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #3
Rene,
OleDbParameters are added by position not by name. Usually you indicate
them in the CommandText with just a ? character. You need to add your
parameters in the order they occur in the Update statement, i.e. Name, URL,
and then ID. This should work assuming all the variable types match up.

Ron Allen
"René Kabis" <re**@kabis.org > wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
People, I am at my wit's end.

I am using the exact code from
http://aspnet.4guysfromrolla.com/articles/071002-1.aspx

And yet, the code does not manage to update the database. When I go to
update my database, I am able to get the form fields, and I am able to
replace the data, but when I go "update", the old data remains.

I have done everything correct, including this:
http://datawebcontrols.com/faqs/Edit...NotSaved.shtml
And yet the db will still not update.

Below is a copy of my code:
<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="Syst em.Data" %>
<% @Import Namespace="Syst em.Data.OleDb" %>
<% @Import Namespace="Syst em.Configuratio n" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="U ser-Agent"%>
<%@ Register TagPrefix="METZ " TagName="Meta" Src="/ssi/meta.ascx" %>
<%@ Register TagPrefix="METZ " TagName="Head" Src="/ssi/head.ascx" %>
<%@ Register TagPrefix="METZ " TagName="Foot" Src="/ssi/foot.ascx" %>
<METZ:Meta Id="ctlMeta" Runat="Server" />
<METZ:Head Id="ctlHead" Runat="Server" />
<script language="vb" runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
Dim myCmd as New OleDbCommand("S ELECT * FROM tblCarLinks", myConn)
myConn.Open()
dgCarLinks.Data Source =
myCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection)
dgCarLinks.Data Bind() myConn.Close() 'Close the connection
End Sub

Sub dgCarLinks_Edit (sender As Object, e As DataGridCommand EventArgs)
dgCarLinks.Edit ItemIndex = e.Item.ItemInde x
BindData()
End Sub

Sub dgCarLinks_Upda te(sender As Object, e As DataGridCommand EventArgs)
'Read in the values of the updated row
Dim iID as Integer = e.Item.Cells(0) .Text
Dim strName as String = CType(e.Item.Ce lls(1).Controls (0),
TextBox).Text
Dim strURL as String = CType(e.Item.Ce lls(2).Controls (0),
TextBox).Text
'Construct the SQL statement using Parameters
Dim strSQL as String = "UPDATE [tblCarLinks] SET [CarLinksName]=@Name,
[CarLinksURL]=@URL WHERE [ID]=@ID"

Dim objConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
objConn.Open()

Dim myCommand as OleDbCommand = new OleDbCommand(st rSQL, objConn)
' myCommand.Comma ndType = CommandType.Tex t

' Add Parameters to the SQL query
Dim parameterID as OleDbParameter = new OleDbParameter( "@ID",
OleDbType.Integ er)
parameterID.Val ue = iID
myCommand.Param eters.Add(param eterID)

Dim parameterName as OleDbParameter = new OleDbParameter( "@Name",
OleDbType.VarWC har)
parameterName.V alue = strName
myCommand.Param eters.Add(param eterName)

Dim parameterURL as OleDbParameter = new OleDbParameter( "@URL",
OleDbType.VarWC har)
parameterURL.Va lue = strURL
myCommand.Param eters.Add(param eterURL)

myCommand.Execu teNonQuery() 'Execute the UPDATE query

objConn.Close() 'Close the connection
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgCarLinks.Edit ItemIndex = -1
BindData()
End Sub
Sub dgCarLinks_Canc el(sender As Object, e As DataGridCommand EventArgs)
dgCarLinks.Edit ItemIndex = -1
BindData()
End Sub
</script>
<div id="content">
<h2>Cool Car Links</h2>
<form runat="server">
<asp:datagrid id="dgCarLinks " runat="server"
showheader="tru e"
autogeneratecol umns="False"
edititemstyle-backcolor="#ffc ccc"
oneditcommand=" dgCarLinks_Edit "
onupdatecommand ="dgCarLinks_Up date"
oncancelcommand ="dgCarLinks_Ca ncel"
cellpadding="10 "
width="100%">
<HeaderStyle backcolor="#000 000" forecolor="#fff fff" font-bold="true"
horizontalalign ="center" />
<ItemStyle backcolor="#fff fff" forecolor="#000 000" />
<AlternatingIte mStyle backcolor="#ccc ccc" />
<Columns>
<asp:BoundColum n DataField="ID" HeaderText="ID" ReadOnly="true" />
<asp:BoundColum n DataField="CarL inksName" HeaderText="Sit e Name" />
<asp:BoundColum n DataField="CarL inksURL" HeaderText="Sit e URL" />
<asp:EditComman dColumn EditText="Edit" ButtonType="Pus hButton"
UpdateText="Upd ate" CancelText="Can cel" />
</Columns>
</asp:datagrid>
</form>
</div>
<METZ:Foot Id="ctlFoot" Runat="Server" />

I hope that someone with sharper eyes than me can figure this monster out.

...Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********

Nov 19 '05 #4
Here you go, again! See the thread posted yesterday by JeremyGrand.

"René Kabis" <re**@kabis.org > wrote in message
news:#t******** ******@TK2MSFTN GP14.phx.gbl...
People, I am at my wit's end.

I am using the exact code from
http://aspnet.4guysfromrolla.com/articles/071002-1.aspx

And yet, the code does not manage to update the database. When I go to
update my database, I am able to get the form fields, and I am able to
replace the data, but when I go "update", the old data remains.

I have done everything correct, including this:
http://datawebcontrols.com/faqs/Edit...NotSaved.shtml
And yet the db will still not update.

Below is a copy of my code:
<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="Syst em.Data" %>
<% @Import Namespace="Syst em.Data.OleDb" %>
<% @Import Namespace="Syst em.Configuratio n" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="U ser-Agent"%>
<%@ Register TagPrefix="METZ " TagName="Meta" Src="/ssi/meta.ascx" %>
<%@ Register TagPrefix="METZ " TagName="Head" Src="/ssi/head.ascx" %>
<%@ Register TagPrefix="METZ " TagName="Foot" Src="/ssi/foot.ascx" %>
<METZ:Meta Id="ctlMeta" Runat="Server" />
<METZ:Head Id="ctlHead" Runat="Server" />
<script language="vb" runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
Dim myCmd as New OleDbCommand("S ELECT * FROM tblCarLinks", myConn)
myConn.Open()
dgCarLinks.Data Source =
myCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection)
dgCarLinks.Data Bind()
myConn.Close() 'Close the connection
End Sub

Sub dgCarLinks_Edit (sender As Object, e As DataGridCommand EventArgs)
dgCarLinks.Edit ItemIndex = e.Item.ItemInde x
BindData()
End Sub

Sub dgCarLinks_Upda te(sender As Object, e As DataGridCommand EventArgs)
'Read in the values of the updated row
Dim iID as Integer = e.Item.Cells(0) .Text
Dim strName as String = CType(e.Item.Ce lls(1).Controls (0),
TextBox).Text
Dim strURL as String = CType(e.Item.Ce lls(2).Controls (0), TextBox).Text 'Construct the SQL statement using Parameters
Dim strSQL as String = "UPDATE [tblCarLinks] SET
[CarLinksName]=@Name, [CarLinksURL]=@URL WHERE [ID]=@ID"

Dim objConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
objConn.Open()

Dim myCommand as OleDbCommand = new OleDbCommand(st rSQL, objConn)
' myCommand.Comma ndType = CommandType.Tex t

' Add Parameters to the SQL query
Dim parameterID as OleDbParameter = new OleDbParameter( "@ID",
OleDbType.Integ er)
parameterID.Val ue = iID
myCommand.Param eters.Add(param eterID)

Dim parameterName as OleDbParameter = new OleDbParameter( "@Name",
OleDbType.VarWC har)
parameterName.V alue = strName
myCommand.Param eters.Add(param eterName)

Dim parameterURL as OleDbParameter = new OleDbParameter( "@URL",
OleDbType.VarWC har)
parameterURL.Va lue = strURL
myCommand.Param eters.Add(param eterURL)

myCommand.Execu teNonQuery() 'Execute the UPDATE query

objConn.Close() 'Close the connection
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgCarLinks.Edit ItemIndex = -1
BindData()
End Sub
Sub dgCarLinks_Canc el(sender As Object, e As DataGridCommand EventArgs)
dgCarLinks.Edit ItemIndex = -1
BindData()
End Sub
</script>
<div id="content">
<h2>Cool Car Links</h2>
<form runat="server">
<asp:datagrid id="dgCarLinks " runat="server"
showheader="tru e"
autogeneratecol umns="False"
edititemstyle-backcolor="#ffc ccc"
oneditcommand=" dgCarLinks_Edit "
onupdatecommand ="dgCarLinks_Up date"
oncancelcommand ="dgCarLinks_Ca ncel"
cellpadding="10 "
width="100%">
<HeaderStyle backcolor="#000 000" forecolor="#fff fff" font-bold="true"
horizontalalign ="center" />
<ItemStyle backcolor="#fff fff" forecolor="#000 000" />
<AlternatingIte mStyle backcolor="#ccc ccc" />
<Columns>
<asp:BoundColum n DataField="ID" HeaderText="ID" ReadOnly="true" />
<asp:BoundColum n DataField="CarL inksName" HeaderText="Sit e Name" />
<asp:BoundColum n DataField="CarL inksURL" HeaderText="Sit e URL" />
<asp:EditComman dColumn EditText="Edit" ButtonType="Pus hButton"
UpdateText="Upd ate" CancelText="Can cel" />
</Columns>
</asp:datagrid>
</form>
</div>
<METZ:Foot Id="ctlFoot" Runat="Server" />

I hope that someone with sharper eyes than me can figure this monster out.

...Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2025
by: Funbeat | last post by:
Hi everybody, A very strange problem with WebControls : A Datagrid in an ASp.net application; Bound with a dataset through ado.net; The updatable columns are dynamically created; When I try to update my DataGrid, I access the cols by means of e.Item.Cells.Count (OnUpdate event) and there :
2
5678
by: Manish | last post by:
Hey folks I am having a weird problem in ASP .Net. My page is in C#. I have a datagrid, which populates based on selection in drop down box on ASP page. This datagrid has template textbox colum in itemtemplate. Datagrid is something like this- Category Week Amt Week% Button Revenue 1 100 Update Revenue 2 200 Update Cost 1 25 25
4
5313
by: Reney | last post by:
I have a very weird problem in updating my datagrid. Please help me to solve it. The datagrid is tied to a dataset table with five columns. Three of them are primary key and the other two columns are the ones that are of interest. These two columns have "date" type values and shows short time (i.e. 11:39). The program updates the database if I change the values in these columns, or add a new record, or delete a record. But, if one of...
5
2036
by: jason | last post by:
Hi, all How can I update data (multiple rows, but not every rows) using dataset in datagrid? I mean is there any way I can let datagrid know which row(s)/column(s) has been modified and update them at database? Thanks.
1
2028
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da browsers and click update it gave me this error: Specified argument was out of the range of valid values. Parameter name:
3
1815
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way when the user saves the data I can use the data already in the datagrid. Typically the user will add several rows before the DataSet.HasChanges is called and the DataAdapter.Update(AllChanges) is called. I want to add an employee number to each...
4
2319
by: George | last post by:
Hi all, I am having trouble with updating my data in an Access database. here is my code: Imports System.Data.OleDb Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
0
1251
by: Tommaso Caldarola | last post by:
I have a custom collection of custom objects. I bind a DataGrid with collection1, a property of custom object is a ReferenceType (another custom object). For that property in the datagrid I see a combobx, when the user selects an item I get the following error: Unable to update data. Unable to convert System.String to CustomObject type.
0
1401
by: geeteshss | last post by:
the present problem is that i am unable to display data in datagrid....... but the data is visible in database..below is the code what should i do...earlier i could view it also below this code is the code which is in my html page plz help........ private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { BindData(); }
0
9658
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10828
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10534
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10244
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7775
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5644
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.