Solved

Update GridView of ASP.net Project

Posted on 2013-05-14
11
234 Views
Last Modified: 2013-06-19
I am trying to add an update row to my gridview, unfortunately, I am unable to get that to work even though my select, delete and cancel work.  How would I do this?  Thanks.  Please see my code below:

<asp:SqlDataSource ID="sqldataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:FileLibraryConnection %>" 
    DeleteCommand="spDeleteDeploymentInfoById" DeleteCommandType="StoredProcedure" 
    InsertCommand="spInsertDeploymentInfo" InsertCommandType="StoredProcedure" 
    SelectCommand="spGetAllDeploymentInfo" SelectCommandType="StoredProcedure"
    UpdateCommand="UPDATE dbo.deploymentInfo
SET 
DeploymentSiteRoot = @DeploymentSiteRoot,
dbservername = dbservername,
MSAccessServiceAccount = @MSAccessServiceAccount,
MSExcelServiceAccount = @MSExcelServiceAccount,
MSPPointServiceAccount = @MSPPointServiceAccount,
MSVisioServiceAccount = @MSVisioServiceAccount,
MSWordServiceAccount = @MSWordServiceAccount,
MSRootWebServiceAccount = @MSRootWebServiceAccount,
TimeofCreation = @TimeofCreation,
UpdateTime = GETDATE()
WHERE
DeploymentId = @DeploymentId">    
    <DeleteParameters>
        <asp:Parameter Name="DeploymentId" Type="Int32" />
    </DeleteParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" 
    AutoGenerateEditButton="true"
    AutoGenerateColumns="False" 
    DataSourceID="sqldataSource1" 
    OnRowUpdating="GridView1_RowUpdating"
    BorderStyle="Solid" BorderColor="Black" DataKeyNames="DeploymentID">    
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
            ShowSelectButton="True" ShowInsertButton="True" />        
        <asp:BoundField DataField="DeploymentSiteRoot" HeaderText="DeploymentSiteRoot" 
            SortExpression="DeploymentSiteRoot" />
        <asp:BoundField DataField="dbservername" HeaderText="dbservername"
            SortExpression="dbservername" />
        <asp:BoundField DataField="MSAccessServiceAccount" 
            HeaderText="MSAccessServiceAccount" SortExpression="MSAccessServiceAccount" />
        <asp:BoundField DataField="MSExcelServiceAccount" 
            HeaderText="MSExcelServiceAccount" SortExpression="MSExcelServiceAccount" />
        <asp:BoundField DataField="MSPPointServiceAccount" 
            HeaderText="MSPPointServiceAccount" SortExpression="MSPPointServiceAccount" />
        <asp:BoundField DataField="MSVisioServiceAccount" 
            HeaderText="MSVisoServiceAccount" SortExpression="MSVisioServiceAccount" />
        <asp:BoundField DataField="MSWordServiceAccount" 
            HeaderText="MSWordServiceAccount" SortExpression="MSWordServiceAccount" />
        <asp:BoundField DataField="MSRootWebServiceAccount" 
            HeaderText="MSRootWebServiceAccount" SortExpression="MSRootWebServiceAccount" />
        <asp:BoundField DataField="TimeofCreation" HeaderText="TimeofCreation" 
            SortExpression="TimeofCreation" />
        <asp:BoundField DataField="UpdateTime" HeaderText="UpdateTime" SortExpression="UpdateTime" />
    </Columns>
</asp:GridView>

Open in new window

0
Comment
Question by:VBBRett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 375 total points
ID: 39166655
Please post:
The exact error message/exception you have.
The CREATE table SQL of the target table.

I assume you tested that the update statement works OK in SQL server.

One way to detect error is to add this event to gridview: (OnRowUpdated=”grdv_RowUpdated”)
protected void grdv_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
{
lblError.Text = e.Exception.Message;
e.ExceptionHandled = true;
}
}

Open in new window

0
 

Author Comment

by:VBBRett
ID: 39166767
No error message at all, it just doesn't update the grid row
0
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 375 total points
ID: 39166849
Does the update action update the database table DeploymentSiteRoot?
Does the grdv_RowUpdated event shows an y exception?
Has the sql user (connection string) has update permissions?
What version SQL server/VS are you using?

Another possible cause is that the select statement (being sp) does not define the sql parameters, if this is the case you need to specify
<UpdateParameters>                    
    <asp:Parameter Name="DeploymentId" Type="Int32" />
//and so on
</UpdateParameters>

Open in new window


Note: Please provide all info requested on previous post as well to avoid guessing work.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:VBBRett
ID: 39167112
Here is my update command as can be seen in the above Sqldatasource:

UpdateCommand="UPDATE dbo.deploymentInfo
SET 
DeploymentSiteRoot = @DeploymentSiteRoot,
dbservername = dbservername,
MSAccessServiceAccount = @MSAccessServiceAccount,
MSExcelServiceAccount = @MSExcelServiceAccount,
MSPPointServiceAccount = @MSPPointServiceAccount,
MSVisioServiceAccount = @MSVisioServiceAccount,
MSWordServiceAccount = @MSWordServiceAccount,
MSRootWebServiceAccount = @MSRootWebServiceAccount,
TimeofCreation = @TimeofCreation,
UpdateTime = GETDATE()
WHERE
DeploymentId = @DeploymentId">

Open in new window


Yes, the user is an admin and has update permissions.  I am using SQL Server 2008 R2 and Visual Studio 2010
0
 

Author Comment

by:VBBRett
ID: 39167116
Here is the code that I do have...

<asp:SqlDataSource ID="sqldataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:FileLibraryConnection %>" 
    DeleteCommand="spDeleteDeploymentInfoById" DeleteCommandType="StoredProcedure" 
    InsertCommand="spInsertDeploymentInfo" InsertCommandType="StoredProcedure" 
    SelectCommand="spGetAllDeploymentInfo" SelectCommandType="StoredProcedure"
    UpdateCommand="UPDATE dbo.deploymentInfo
SET 
DeploymentSiteRoot = @DeploymentSiteRoot,
dbservername = dbservername,
MSAccessServiceAccount = @MSAccessServiceAccount,
MSExcelServiceAccount = @MSExcelServiceAccount,
MSPPointServiceAccount = @MSPPointServiceAccount,
MSVisioServiceAccount = @MSVisioServiceAccount,
MSWordServiceAccount = @MSWordServiceAccount,
MSRootWebServiceAccount = @MSRootWebServiceAccount,
TimeofCreation = @TimeofCreation,
UpdateTime = GETDATE()
WHERE
DeploymentId = @DeploymentId">  
    <UpdateParameters>
        <asp:Parameter Name="DeploymentId" Type="Int32" />
         <asp:Parameter Name="DeploymentSiteRoot" Type="String" />
        <asp:Parameter Name="dbservername" Type="String" />
        <asp:Parameter Name="MSAccessServiceAccount" Type="String" />
        <asp:Parameter Name="MSExcelServiceAccount" Type="String" />
        <asp:Parameter Name="MSPPointServiceAccount" Type="String" />
        <asp:Parameter Name="MSVisioServiceAccount" Type="String" />
        <asp:Parameter Name="MSWordServiceAccount" Type="String" />
        <asp:Parameter Name="MSRootWebServiceAccount" Type="String" />
        <asp:Parameter Name="UpdateTime" Type="DateTime" />
    </UpdateParameters>  
    <DeleteParameters>
        <asp:Parameter Name="DeploymentId" Type="Int32" />
    </DeleteParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" 
    AutoGenerateEditButton="true"
    AutoGenerateColumns="False" 
    DataSourceID="sqldataSource1"        
    BorderStyle="Solid" BorderColor="Black" DataKeyNames="DeploymentID">    
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
            ShowSelectButton="True" ShowInsertButton="True" />        
        <asp:BoundField DataField="DeploymentSiteRoot" HeaderText="DeploymentSiteRoot" 
            SortExpression="DeploymentSiteRoot" />
        <asp:BoundField DataField="dbservername" HeaderText="dbservername"
            SortExpression="dbservername" />
        <asp:BoundField DataField="MSAccessServiceAccount" 
            HeaderText="MSAccessServiceAccount" SortExpression="MSAccessServiceAccount" />
        <asp:BoundField DataField="MSExcelServiceAccount" 
            HeaderText="MSExcelServiceAccount" SortExpression="MSExcelServiceAccount" />
        <asp:BoundField DataField="MSPPointServiceAccount" 
            HeaderText="MSPPointServiceAccount" SortExpression="MSPPointServiceAccount" />
        <asp:BoundField DataField="MSVisioServiceAccount" 
            HeaderText="MSVisoServiceAccount" SortExpression="MSVisioServiceAccount" />
        <asp:BoundField DataField="MSWordServiceAccount" 
            HeaderText="MSWordServiceAccount" SortExpression="MSWordServiceAccount" />
        <asp:BoundField DataField="MSRootWebServiceAccount" 
            HeaderText="MSRootWebServiceAccount" SortExpression="MSRootWebServiceAccount" />
        <asp:BoundField DataField="TimeofCreation" HeaderText="TimeofCreation" 
            SortExpression="TimeofCreation" />
        <asp:BoundField DataField="UpdateTime" HeaderText="UpdateTime" SortExpression="UpdateTime" />
    </Columns>
</asp:GridView>

Open in new window

0
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 375 total points
ID: 39167303
Please post:
- The CREATE table SQL of the target table.
the answers to:
- Does the update action update the database table DeploymentSiteRoot? You can check that by inspecting the database and the SQL server logs - e.g profiler log. I need that to determine if the problem is in your page and what kind of error is logged.
- Does the grdv_RowUpdated event shows any exception at e.Exception?IF so please post it.
- Does the update statement runs OK in SQL server MS with the test values that are not updating in the gridview?
0
 
LVL 13

Assisted Solution

by:Jitendra Patil
Jitendra Patil earned 125 total points
ID: 39167641
hi VBBRett
i think you should check the below line in your code

<asp:SqlDataSource ID="sqldataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:FileLibraryConnection %>"
    DeleteCommand="spDeleteDeploymentInfoById" DeleteCommandType="StoredProcedure"
    InsertCommand="spInsertDeploymentInfo" InsertCommandType="StoredProcedure"
    SelectCommand="spGetAllDeploymentInfo" SelectCommandType="StoredProcedure"
    UpdateCommand="UPDATE dbo.deploymentInfo
SET
DeploymentSiteRoot = @DeploymentSiteRoot,
dbservername = dbservername,
MSAccessServiceAccount = @MSAccessServiceAccount,
MSExcelServiceAccount = @MSExcelServiceAccount,


the above line in bold shows that you are assign a variable value to the parmeter, so it should be:
dbservername = @dbservername,

as you have declared dbservername as variable in the list of update parameters
<UpdateParameters>
        <asp:Parameter Name="DeploymentId" Type="Int32" />
         <asp:Parameter Name="DeploymentSiteRoot" Type="String" />
<asp:Parameter Name="dbservername" Type="String" />
        <asp:Parameter Name="MSAccessServiceAccount" Type="String" />
        <asp:Parameter Name="MSExcelServiceAccount" Type="String" />
        <asp:Parameter Name="MSPPointServiceAccount" Type="String" />
        <asp:Parameter Name="MSVisioServiceAccount" Type="String" />
        <asp:Parameter Name="MSWordServiceAccount" Type="String" />
        <asp:Parameter Name="MSRootWebServiceAccount" Type="String" />
        <asp:Parameter Name="UpdateTime" Type="DateTime" />
    </UpdateParameters>  

try changing the code and also pass value to the dbservername variable.

hope this helps.
0
 

Author Comment

by:VBBRett
ID: 39168789
Negative, I'm still where I left off.  The update query works but for some reason, the parameters are not matching up the text box field names to the sql parameters.  I ran an example and as opposed to having @dbservername, I typed in 'test'.  'test' was inserted into that field and the data was updated just fine.  So, how do I get it so that my update query reads the gridview textboxes like it is supposed to?
0
 

Accepted Solution

by:
VBBRett earned 0 total points
ID: 39248223
Ok, so it appears that once I took the DeploymentId out as an Update Parameter on the <UpdateParamaters> section, I was good to go.  Since the DeploymentId is a Primary Key and is stated as such in the grid, I did not need to add the DeploymentId as a paramater in the Update Parameters section.
0
 

Author Comment

by:VBBRett
ID: 39248230
I'll still give points or effort, but the answer is what I stated above.
0
 

Author Closing Comment

by:VBBRett
ID: 39258781
My answer was the overall correct answer.  All other explanations were good explanations and keypoints for other users, but I was the only one to find the correct resolution.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question