473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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="System.Data" %>
<% @Import Namespace="System.Data.OleDb" %>
<% @Import Namespace="System.Configuration" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="User-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(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("SELECT * FROM tblCarLinks", myConn)
myConn.Open()
dgCarLinks.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
dgCarLinks.DataBind()
myConn.Close() 'Close the connection
End Sub

Sub dgCarLinks_Edit(sender As Object, e As DataGridCommandEventArgs)
dgCarLinks.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub

Sub dgCarLinks_Update(sender As Object, e As DataGridCommandEventArgs)
'Read in the values of the updated row
Dim iID as Integer = e.Item.Cells(0).Text
Dim strName as String = CType(e.Item.Cells(1).Controls(0),
TextBox).Text
Dim strURL as String = CType(e.Item.Cells(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(ConfigurationSettings.AppSettings( "strConn"))
objConn.Open()

Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
' myCommand.CommandType = CommandType.Text

' Add Parameters to the SQL query
Dim parameterID as OleDbParameter = new OleDbParameter("@ID",
OleDbType.Integer)
parameterID.Value = iID
myCommand.Parameters.Add(parameterID)

Dim parameterName as OleDbParameter = new OleDbParameter("@Name",
OleDbType.VarWChar)
parameterName.Value = strName
myCommand.Parameters.Add(parameterName)

Dim parameterURL as OleDbParameter = new OleDbParameter("@URL",
OleDbType.VarWChar)
parameterURL.Value = strURL
myCommand.Parameters.Add(parameterURL)

myCommand.ExecuteNonQuery() 'Execute the UPDATE query

objConn.Close() 'Close the connection
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgCarLinks.EditItemIndex = -1
BindData()
End Sub
Sub dgCarLinks_Cancel(sender As Object, e As DataGridCommandEventArgs)
dgCarLinks.EditItemIndex = -1
BindData()
End Sub
</script>
<div id="content">
<h2>Cool Car Links</h2>
<form runat="server">
<asp:datagrid id="dgCarLinks" runat="server"
showheader="true"
autogeneratecolumns="False"
edititemstyle-backcolor="#ffcccc"
oneditcommand="dgCarLinks_Edit"
onupdatecommand="dgCarLinks_Update"
oncancelcommand="dgCarLinks_Cancel"
cellpadding="10"
width="100%">
<HeaderStyle backcolor="#000000" forecolor="#ffffff" font-bold="true"
horizontalalign="center" />
<ItemStyle backcolor="#ffffff" forecolor="#000000" />
<AlternatingItemStyle backcolor="#cccccc" />
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID" ReadOnly="true" />
<asp:BoundColumn DataField="CarLinksName" HeaderText="Site Name" />
<asp:BoundColumn DataField="CarLinksURL" HeaderText="Site URL" />
<asp:EditCommandColumn EditText="Edit" ButtonType="PushButton"
UpdateText="Update" CancelText="Cancel" />
</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 1636
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****************@TK2MSFTNGP14.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="System.Data" %>
<% @Import Namespace="System.Data.OleDb" %>
<% @Import Namespace="System.Configuration" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="User-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(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("SELECT * FROM tblCarLinks", myConn)
myConn.Open()
dgCarLinks.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
dgCarLinks.DataBind() myConn.Close() 'Close the connection
End Sub

Sub dgCarLinks_Edit(sender As Object, e As DataGridCommandEventArgs)
dgCarLinks.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub

Sub dgCarLinks_Update(sender As Object, e As DataGridCommandEventArgs)
'Read in the values of the updated row
Dim iID as Integer = e.Item.Cells(0).Text
Dim strName as String = CType(e.Item.Cells(1).Controls(0),
TextBox).Text
Dim strURL as String = CType(e.Item.Cells(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(ConfigurationSettings.AppSettings( "strConn"))
objConn.Open()

Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
' myCommand.CommandType = CommandType.Text

' Add Parameters to the SQL query
Dim parameterID as OleDbParameter = new OleDbParameter("@ID",
OleDbType.Integer)
parameterID.Value = iID
myCommand.Parameters.Add(parameterID)

Dim parameterName as OleDbParameter = new OleDbParameter("@Name",
OleDbType.VarWChar)
parameterName.Value = strName
myCommand.Parameters.Add(parameterName)

Dim parameterURL as OleDbParameter = new OleDbParameter("@URL",
OleDbType.VarWChar)
parameterURL.Value = strURL
myCommand.Parameters.Add(parameterURL)

myCommand.ExecuteNonQuery() 'Execute the UPDATE query

objConn.Close() 'Close the connection
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgCarLinks.EditItemIndex = -1
BindData()
End Sub
Sub dgCarLinks_Cancel(sender As Object, e As DataGridCommandEventArgs)
dgCarLinks.EditItemIndex = -1
BindData()
End Sub
</script>
<div id="content">
<h2>Cool Car Links</h2>
<form runat="server">
<asp:datagrid id="dgCarLinks" runat="server"
showheader="true"
autogeneratecolumns="False"
edititemstyle-backcolor="#ffcccc"
oneditcommand="dgCarLinks_Edit"
onupdatecommand="dgCarLinks_Update"
oncancelcommand="dgCarLinks_Cancel"
cellpadding="10"
width="100%">
<HeaderStyle backcolor="#000000" forecolor="#ffffff" font-bold="true"
horizontalalign="center" />
<ItemStyle backcolor="#ffffff" forecolor="#000000" />
<AlternatingItemStyle backcolor="#cccccc" />
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID" ReadOnly="true" />
<asp:BoundColumn DataField="CarLinksName" HeaderText="Site Name" />
<asp:BoundColumn DataField="CarLinksURL" HeaderText="Site URL" />
<asp:EditCommandColumn EditText="Edit" ButtonType="PushButton"
UpdateText="Update" CancelText="Cancel" />
</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**************@TK2MSFTNGP14.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="System.Data" %>
<% @Import Namespace="System.Data.OleDb" %>
<% @Import Namespace="System.Configuration" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="User-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(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("SELECT * FROM tblCarLinks", myConn)
myConn.Open()
dgCarLinks.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
dgCarLinks.DataBind()
myConn.Close() 'Close the connection
End Sub

Sub dgCarLinks_Edit(sender As Object, e As DataGridCommandEventArgs)
dgCarLinks.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub

Sub dgCarLinks_Update(sender As Object, e As DataGridCommandEventArgs)
'Read in the values of the updated row
Dim iID as Integer = e.Item.Cells(0).Text
Dim strName as String = CType(e.Item.Cells(1).Controls(0),
TextBox).Text
Dim strURL as String = CType(e.Item.Cells(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(ConfigurationSettings.AppSettings( "strConn"))
objConn.Open()

Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
' myCommand.CommandType = CommandType.Text

' Add Parameters to the SQL query
Dim parameterID as OleDbParameter = new OleDbParameter("@ID",
OleDbType.Integer)
parameterID.Value = iID
myCommand.Parameters.Add(parameterID)

Dim parameterName as OleDbParameter = new OleDbParameter("@Name",
OleDbType.VarWChar)
parameterName.Value = strName
myCommand.Parameters.Add(parameterName)

Dim parameterURL as OleDbParameter = new OleDbParameter("@URL",
OleDbType.VarWChar)
parameterURL.Value = strURL
myCommand.Parameters.Add(parameterURL)

myCommand.ExecuteNonQuery() 'Execute the UPDATE query

objConn.Close() 'Close the connection
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgCarLinks.EditItemIndex = -1
BindData()
End Sub
Sub dgCarLinks_Cancel(sender As Object, e As DataGridCommandEventArgs)
dgCarLinks.EditItemIndex = -1
BindData()
End Sub
</script>
<div id="content">
<h2>Cool Car Links</h2>
<form runat="server">
<asp:datagrid id="dgCarLinks" runat="server"
showheader="true"
autogeneratecolumns="False"
edititemstyle-backcolor="#ffcccc"
oneditcommand="dgCarLinks_Edit"
onupdatecommand="dgCarLinks_Update"
oncancelcommand="dgCarLinks_Cancel"
cellpadding="10"
width="100%">
<HeaderStyle backcolor="#000000" forecolor="#ffffff" font-bold="true"
horizontalalign="center" />
<ItemStyle backcolor="#ffffff" forecolor="#000000" />
<AlternatingItemStyle backcolor="#cccccc" />
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID" ReadOnly="true" />
<asp:BoundColumn DataField="CarLinksName" HeaderText="Site Name" />
<asp:BoundColumn DataField="CarLinksURL" HeaderText="Site URL" />
<asp:EditCommandColumn EditText="Edit" ButtonType="PushButton"
UpdateText="Update" CancelText="Cancel" />
</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
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...
2
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...
4
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...
5
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...
1
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...
3
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...
4
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,...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.