473,396 Members | 1,743 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,396 software developers and data experts.

Update Command not working with Gridview

ihaveaquery
Hi,
Delete is working fine for me, but Update- Nothing is happening. Please find the code snippet below and help me out...
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="empGrid" runat="server" AllowSorting="True" AutoGenerateColumns="False"
  2.             DataSourceID="empTestDataSource" >
  3.             <Columns>
  4.                 <asp:ButtonField    CommandName="Select"    ButtonType=Link         DataTextField="empId" />              
  5.                 <asp:BoundField     DataField="empName"     HeaderText="empName"    SortExpression="empName" />
  6.                 <asp:BoundField     DataField="empAge"      HeaderText="empAge"     SortExpression="empAge" />
  7.                 <asp:CommandField   ShowEditButton=true     ButtonType=Button />
  8.                 <asp:CommandField   ShowDeleteButton=true   ButtonType=Button />
  9.             </Columns>
  10.         </asp:GridView>
  11.         <asp:AccessDataSource ID="empTestDataSource" runat="server" DataFile="~/Database/Employee.mdb"
  12.             SelectCommand="SELECT [empName], [empAge], [empId] FROM [emp]"
  13.             UpdateCommand="UPDATE emp SET empName=@empName WHERE empId=@empId"
  14.             DeleteCommand="DELETE FROM emp WHERE empId=@empId" OldValuesParameterFormatString="{0}">
  15.             <UpdateParameters>
  16.                 <asp:Parameter Name="empName" Type=string />
  17.                 <asp:Parameter Name="empId" Type=Int32 />
  18.             </UpdateParameters>
  19.         </asp:AccessDataSource>
Any help would be appreciated....
thnks in advance...
Feb 28 '07 #1
9 25673
kenobewan
4,871 Expert 4TB
How are you executing the update statement?
Mar 1 '07 #2
On clicking the delete button, i get the row deleted from the DB. But, Update is not working as it is suppsoed to work. I am not getting any error, the page returns with the original values.
Am i missing something in the code? Pls help...
Mar 1 '07 #3
Somebody pls help....
I am using a simple Gridview to display the emp id (as a link for selecting), emp name, emp Age. There are edit and delete buttons in each row. Using the delete button, the record can be deleted. But the Edit-Update/Cancel functinality is not working. I am not getting any errors. The old values are not updated with the new values. This is the scenario. The code is once more put for reference...PLS HELP !!!

Expand|Select|Wrap|Line Numbers
  1. <table width="500px"><tr><td>
  2. <div style="margin:5px; margin-top:5px">
  3.     <div class="smallfont" style="margin-bottom:2px">Code:</div>
  4.     <pre class="alt2 smallcode" style="margin:0px; padding:6px; border:1px inset; width: 500px; overflow:scroll"><div dir="ltr" style="text-align:left;">&lt;asp:GridView ID=&quot;empGrid&quot; runat=&quot;server&quot; AllowSorting=&quot;True&quot; AutoGenerateColumns=&quot;False&quot;
  5.             DataSourceID=&quot;empTestDataSource&quot; &gt;
  6.             &lt;Columns&gt;
  7.                 &lt;asp:ButtonField    CommandName=&quot;Select&quot;    ButtonType=Link         DataTextField=&quot;empId&quot; /&gt;              
  8.                 &lt;asp:BoundField     DataField=&quot;empName&quot;     HeaderText=&quot;empName&quot;    SortExpression=&quot;empName&quot; /&gt;
  9.                 &lt;asp:BoundField     DataField=&quot;empAge&quot;      HeaderText=&quot;empAge&quot;     SortExpression=&quot;empAge&quot; /&gt;
  10.                 &lt;asp:CommandField   ShowEditButton=true     ButtonType=Button /&gt;
  11.                 &lt;asp:CommandField   ShowDeleteButton=true   ButtonType=Button /&gt;
  12.             &lt;/Columns&gt;
  13.         &lt;/asp:GridView&gt;
  14.         &lt;asp:AccessDataSource ID=&quot;empTestDataSource&quot; runat=&quot;server&quot; DataFile=&quot;~/Database/Employee.mdb&quot;
  15.             SelectCommand=&quot;SELECT [empName], [empAge], [empId] FROM [emp]&quot;
  16.             UpdateCommand=&quot;UPDATE emp SET empName=@empName WHERE empId=@empId&quot;
  17.             DeleteCommand=&quot;DELETE FROM emp WHERE empId=@empId&quot; OldValuesParameterFormatString=&quot;{0}&quot;&gt;
  18.             &lt;UpdateParameters&gt;
  19.                 &lt;asp:Parameter Name=&quot;empName&quot; Type=string /&gt;
  20.                 &lt;asp:Parameter Name=&quot;empId&quot; Type=Int32 /&gt;
  21.             &lt;/UpdateParameters&gt;
  22.         &lt;/asp:AccessDataSource&gt;</div></pre>
  23. </div>
  24. </td></tr></table><br />
Mar 2 '07 #4
kenobewan
4,871 Expert 4TB
Are you refreshing the dataqsource? Otherwise gridview is going ti display same values.
Mar 3 '07 #5
Are you refreshing the dataqsource? Otherwise gridview is going ti display same values.
But the value is not getting updated in the database even.
And how do we refresh a datasource? Pls help...
Mar 6 '07 #6
kenobewan
4,871 Expert 4TB
I was thinking that if your gridview is rebound then the updated data would be displayed. You indicate that it is the former so that your update command isn't executing. Here is an article that may help:
ASP.NET GridView - Add a new record
Mar 7 '07 #7
I had the same problem. I found that in Visual Web Developer I had to specify the "DataKeyNames" property of the GridView as the primary key for my database table.

So the primary key for my database table was "id". So I clicked on the GridView and in the Properties tab, I typed "id" (no quotes) in the "DataKeyNames" box.

Hope that helps,
marloutor
Mar 22 '07 #8
calico
1
Thanks! This was very helpful.

I had the same problem. I found that in Visual Web Developer I had to specify the "DataKeyNames" property of the GridView as the primary key for my database table.

So the primary key for my database table was "id". So I clicked on the GridView and in the Properties tab, I typed "id" (no quotes) in the "DataKeyNames" box.

Hope that helps,
marloutor
Apr 9 '07 #9
I also had a problem with a GridView that was not updating. Inspection of the e.Newvalues Dictionary in the GridView's RowUpdating event showed that the old values for the record were being sent to the database UPDATE query. DataKeyNames was not my problem; I had it set correctly. The WHERE clause of my SELECT query referenced a control parameter against a TextBox on my form. I had inadvertently set EnableViewState for this textbox to "False". Because of this, the GridView was rebinding itself before the UPDATE occurred. Setting EnableViewState on the TextBox to "True" fixed the problem.

Expand|Select|Wrap|Line Numbers
  1.         Protected Sub MyGridView_RowUpdating _
  2.         (sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) _
  3.         Handles MyGridView.RowUpdating
  4.  
  5.         ' Inspect the parameters being sent to the database for an ASP NET GridView UPDATE.
  6.  
  7.         Dim I As Integer
  8.  
  9.         I = 0
  10.  
  11.         For Each MVO As System.Collections.DictionaryEntry In e.OldValues
  12.             If MVO.Value Is DBNull.Value OrElse MVO.Value Is Nothing Then
  13.                 Debug.Print(I.ToString + ": " + MVO.Key + " Value:  ")
  14.             Else
  15.                 Debug.Print(I.ToString + ": " + MVO.Key + " Value:  " + MVO.Value.ToString)
  16.             End If
  17.  
  18.             I += 1
  19.         Next MVO
  20.  
  21.         I = 0
  22.         For Each MVN As System.Collections.DictionaryEntry In e.NewValues
  23.             If MVN.Value Is DBNull.Value OrElse MVN.Value Is Nothing Then
  24.                 Debug.Print(I.ToString + ": " + MVN.Key + " Value:  ")
  25.             Else
  26.                 Debug.Print(I.ToString + ": " + MVN.Key + " Value:  " + MVN.Value.ToString)
  27.             End If
  28.             I += 1
  29.         Next MVN
  30.  
  31.  
  32.     End Sub
  33.  
Sep 4 '14 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: NETDeveloper | last post by:
Hi, I almost have my nested datagrid working properly. I created a datagrid on a user control and dropped that onto another datagrid. At first, I noticed when I was stepping through the code,...
0
by: fatmosh | last post by:
I have a GridView that is pulling data from a SQL database using a Select command. I would like to use GridView's built-in "Edit, Update, Cancel" functionality because it is very handy. However,...
3
by: A_PK | last post by:
Could anyone pls guide me what is wrong with my Update Command Dim signbyte As Byte() signbyte = GetByteArray() ' i create this function to return ByteArray Try Dim cmd As New SqlCeCommand...
0
by: Nick | last post by:
Hi all, I'm trying to use an Update command in a Gridview. I understand about the <asp:Parameter Name="blah" Type="String" /> however, although this is telling .NET what type the parameter is,...
2
by: TJ | last post by:
Hi All, I am having some trouble. I have created a database via the new database option inside VWD2005. Then and table or two. I have been able to perform INSERT and SELECT operations on...
0
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
i get this message when i attempt an update in a gridview where i create the update manuelly. "Updating is not supported by data source 'dsStkStdData' unless UpdateCommand is specified. " ...
1
by: Selvakumar | last post by:
hai friends, I am new to .net programming. I did the inserting data into MS-access database but i couldn't able to perform the update command. I used only textbox and command button for inserting...
3
by: Brad Baker | last post by:
I have a formview with a datasource that contains a select and update command. The select statement works fine but the update command doesn't seem to be working. After some troubleshooting I have...
0
by: Bobby Edward | last post by:
I have a business object method called UpdateCategory that calls the Update command of a xsd dataset I created. The Update has 5 overloads: DataTable, DataSet, DataRow, DataRows(), Actual...
0
by: =?Utf-8?B?ZWdzZGFy?= | last post by:
Hello, I'm trying to do an update in my gridview but it is not doing for "Descripcion" it but with the other field "IdGrupo" it does and I need to save both, how can I solve this: This is my...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
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...

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.