473,748 Members | 7,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview and Updating

Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 20 '06 #1
5 2247
Hi Michael,

If you were using templates make sure that you are using 2-way databinding
expression such as Bind, otherwise, start from a blue print of a code that
works and build on it. Here are some starting demos:
http://www.asp.net/QuickStart/aspnet...spx#twowaybind
http://www.webswapp.com/codesamples/.../gridview.aspx
http://www.webswapp.com/codesamples/...s/default.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Michael" wrote:
Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 20 '06 #2
Hi Phillip,
Thank you so much for the reply. After looking over your suggested reading
and reading some other posts I got the impression that the Edit/Delete
functions only work when you are using a Datasource attached to the
DatasourceId property. Is this correct? Based on that, I have redesigned the
for some using a SqlDataSource attached to the DatasourceId. But I'm getting
the following error when trying to update a row:
Procedure or function Admin_UpdatePOI tem has too many arguments specified.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Data.Sql Client.SqlExcep tion: Procedure or function
Admin_UpdatePOI tem has too many arguments specified.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Now, I have setup the gridview as follows:
<asp:GridView ID="grdPOs" runat="server" AllowPaging="Tr ue"
AutoGenerateCol umns="False"
BackColor="Whit e" BorderColor="#C C9966" BorderStyle="No ne"
BorderWidth="1p x"
CellPadding="4" DataKeyNames="I temId" Height="68px" PageSize="5"
Width="642px" AutoGenerateDel eteButton="True " AutoGenerateEdi tButton="True"
AutoGenerateSel ectButton="True " DataSourceID="P ODetailDataSour ce">
<FooterStyle BackColor="#FFF FCC" ForeColor="#330 099" />
<Columns>
<asp:BoundFie ld DataField="Item ID" HeaderText="Ite m ID"
Visible="False" />
<asp:BoundFie ld DataField="POrd erId" HeaderText="PO Id"
Visible="False" />
<asp:BoundFie ld DataField="Page " HeaderText="Pag e">
<ItemStyle HorizontalAlign ="Right" />
</asp:BoundField>
<asp:BoundFie ld DataField="Cata logId" HeaderText="Cat alog #">
<ItemStyle HorizontalAlign ="Right" Width="80px" />
</asp:BoundField>
<asp:BoundFie ld DataField="Item Description"
HeaderText="Des cription">
<ItemStyle Width="250px" />
</asp:BoundField>
<asp:BoundFie ld DataField="Qty" HeaderText="Qty ">
<ItemStyle HorizontalAlign ="Right" />
</asp:BoundField>
<asp:BoundFie ld DataField="Unit Price"
DataFormatStrin g="{0:C}" HeaderText="Uni tPrice">
<ItemStyle HorizontalAlign ="Right" Width="70px" />
</asp:BoundField>
<asp:BoundFie ld DataFormatStrin g="{0:0.00}"
HeaderText="Tot al" InsertVisible=" False" />
</Columns>
<RowStyle BackColor="Whit e" ForeColor="#330 099" />
<SelectedRowSty le BackColor="#FFC C66" Font-Bold="True"
ForeColor="#663 399" />
<PagerStyle BackColor="#FFF FCC" ForeColor="#330 099"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#990 000" Font-Bold="True"
ForeColor="#FFF FCC" />
</asp:GridView>
And the datasource is as follows:
<asp:SqlDataSou rce ID="PODetailDat aSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:PODetailsCon nectionString %>"
SelectCommand=" admin_GetPODeta ils"
SelectCommandTy pe="StoredProce dure" DeleteCommand=" Admin_DeletePOI tem"
DeleteCommandTy pe="StoredProce dure" InsertCommand=" Admin_AddPOItem s"
InsertCommandTy pe="StoredProce dure" UpdateCommand=" Admin_UpdatePOI tem"
UpdateCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="cmbP ORequests"
Name="POrderId" PropertyName="S electedValue"
Type="Int32" />
</SelectParameter s>
<DeleteParamete rs>
<asp:Paramete r Name="ItemId" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="ItemID" Type="Int32" />
<asp:Paramete r Name="CatalogId " Type="String" />
<asp:Paramete r Name="ItemDescr iption" Type="String" />
<asp:Paramete r Name="Qty" Type="Int32" />
<asp:Paramete r Name="UnitPrice " Type="Decimal" />
<asp:Paramete r Name="Page" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="POrderId" Type="Int32" />
<asp:Paramete r Name="CatalogeI d" Type="String" />
<asp:Paramete r Name="ItemDescr iption" Type="String" />
<asp:Paramete r Name="Qty" Type="Int32" />
<asp:Paramete r Name="UnitPrice " Type="Decimal" />
<asp:Paramete r Name="Page" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
The Stored proc is written as follows:
CREATE PROCEDURE [dbo].[Admin_UpdatePOI tem]
@ItemID int,
@CatalogId varchar(20),
@ItemDescriptio n varchar(250),
@Qty int,
@UnitPrice money,
@Page varchar(10)
AS

Update OrderItems Set
CatalogId = @CatalogId,
ItemDescription = @ItemDescriptio n,
Qty = @Qty,
UnitPrice = @UnitPrice,
Page = @Page
Where ItemID = @ItemID
GO

The research that I've done so far I have found that there is an extra
parameter, so I setup a function to remove the parameter but I still get the
error. Here is the code to delete.
'Serves to tell me what parameters and delete the extra one.
Protected Sub PODetailDataSou rce_Updating(By Val sender As Object, ByVal e As
System.Web.UI.W ebControls.SqlD ataSourceComman dEventArgs) Handles
PODetailDataSou rce.Updating
Dim param As DbParameter
Dim DeleteParam as DbParameter
Debug.WriteLine ("Starting Test")
Debug.WriteLine ("The command has " & e.Command.Param eters.Count.ToS tring
& " parameters altogether.")
For Each param In e.Command.Param eters
if param.Parameter Name.ToString = "@POrderId" then
DeleteParam = param
End If
if param.Parameter Name.ToString.L ength > 1 then
Debug.WriteLine ("parameter " & param.Parameter Name.ToString & "
=> " & (param.Value.To String & "") & "<br>")
end if
Next
if not isnothing(Delet eParam) then
e.Command.Param eters.Remove(De leteParam)
end if
Debug.WriteLine ("Starting Second Test")
Debug.WriteLine ("The command has " & e.Command.Param eters.Count.ToS tring
& " parameters altogether.")
For Each param In e.Command.Param eters
if param.Parameter Name.ToString = "@POrderId" then
DeleteParam = param
End If
if param.Parameter Name.ToString.L ength > 1 then
Debug.WriteLine ("parameter " & param.Parameter Name.ToString & "
=> " & (param.Value.To String & "") & "<br>")
end if
Next
End Sub
After the code is run (before deleting the parameter) I get the following
parameter:
The command has 8 parameters altogether.
parameter @CatalogId => 254-547<br>
parameter @ItemDescriptio n => Testing<br>
parameter @Qty => 5<br>
parameter @UnitPrice => 24.1500<br>
parameter @Page => 55<br>
parameter @ItemId => 3<br>
parameter @POrderId => 1<br> ****Param to remove *****
Starting Second Test
The command has 7 parameters altogether.
parameter @CatalogId => 254-547<br>
parameter @ItemDescriptio n => Testing<br>
parameter @Qty => 5<br>
parameter @UnitPrice => 24.1500<br>
parameter @Page => 55<br>
parameter @ItemId => 3<br>
Sorry for the long message, but I figured you may need to know this info.
What do you think. Thanks for the help.
Michael

Apr 21 '06 #3
Hi Phillip,
I've been testing and researching further. I actually was setting the
DataKeyNames property as follows:

Dim lKeys as String() = {"ItemId", "POrderId"}
grdPOs.DataKeyN ames = lKeys

When I removed the POrderId value the POrderId didn't show up in the debug
output, but still getting the same error. If I look at the number of
parameters that printed out, that number is the same the stored proc. I'm
alittle confused. What the heck is going on here. Thanks
Michael

"Phillip Williams" wrote:
Hi Michael,

If you were using templates make sure that you are using 2-way databinding
expression such as Bind, otherwise, start from a blue print of a code that
works and build on it. Here are some starting demos:
http://www.asp.net/QuickStart/aspnet...spx#twowaybind
http://www.webswapp.com/codesamples/.../gridview.aspx
http://www.webswapp.com/codesamples/...s/default.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Michael" wrote:
Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 21 '06 #4
Hi Again,
One more thing. Based on my stored proc and parameters I should have only 6
parameters, but the PODetailDataSou rce_Updating events reports 7 parameters
and after tracing it down I have a "@" as on of the parametername. WHY? That
would be the extra and its not suppose to be there. Have any ideas.
Thanks
Michael
"Phillip Williams" wrote:
Hi Michael,

If you were using templates make sure that you are using 2-way databinding
expression such as Bind, otherwise, start from a blue print of a code that
works and build on it. Here are some starting demos:
http://www.asp.net/QuickStart/aspnet...spx#twowaybind
http://www.webswapp.com/codesamples/.../gridview.aspx
http://www.webswapp.com/codesamples/...s/default.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Michael" wrote:
Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 21 '06 #5
Hi Again,
Just wanted to let you know that I have it working, but I still had to catch
the "@" parameter and delete it from the list. I still don't know why that
one was there, if you do, please let me know. But at least its working now.
By the way, I should not have to worry about some other out of the blue
parameter that I will have to delete later, right?
Thanks again Phillip for pointing me in the right direction.
Michael

Apr 21 '06 #6

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

Similar topics

1
2033
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass the applicable fields in the gridview to a sqldatasource which in turn calls a sproc with the appropriate parameters and data. Any ideas? Thanks in advance,
3
6336
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data correctly but it is not updating or deleting the rows. What I did was, in design view, added a gridview control and added an sqldatasource control. I configured the data source to update and delete. In the gridview tasks I selected enable...
8
5039
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
5
15331
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying works fine, however programmatically, while the grid will display data that exsists in the database, any operation on the data ( editing/updating/deleting ) seems to cause a rowdeleting/updating etc error. Or is this simply not meant to be done?
0
1377
by: Michael Kellogg | last post by:
I have a problem wherein a query that updates a GridView doesn't seem to really stay in sync with a label I have above the GridView. I have a GridView object that I'm updating with information whenever my user enters a job number into a textbox and hits a button. There is a SQLDataSource object on the page that does the retrieval of the data, and the job number parameter for its query is bound to the textbox "Text" value. In the button...
1
4699
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I have a gridview which I added a <asp:CommandField EditText="E" CancelText="C" UpdateText="U" ButtonType="Link" ShowEditButton="True" /> my gridview looks like this <asp:GridView ID="GridView1" runat="server" OnRowEditing="RowEdit" OnRowCancelingEdit="RowCancel" OnRowUpdating="RowUpdating"...
11
6066
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know if that's what's causing the behavior or not. It seems like the Update button should at least do something. When the Edit button is clicked, the grid goes into Edit mode and the Cancel button takes the grid out of Edit mode. So, I don't get what...
0
4280
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't want to have my parameter names in those methods have to be "original_Parametername" or even if I change the OldValuesParameterFormatString to get rid of the "original" I would still have just "Parametername". I think most people user parameters...
0
1277
by: BizWeb | last post by:
Hi, i am new to ASP.NET. I have write a very simple code to try the updating of the GridView but it is not updating the data. Below is the simple code that i have use. <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
1793
by: xMetalDetectorx | last post by:
Hi Everyone, I have a very simple web app that uses .Net 2.0 login control to authenticate users and allow access to an "admin" folder. Inside that admin folder I have one page that has a SQLDataSource and a GridView control. I am using the GridView to test updating a very simple table in the database. The problem is, it will not Update the record at all! I placed this code outside of the admin folder and it worked fine. What could be causing...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
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
9366
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
8239
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
6793
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
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
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...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2211
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.