Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update GridView of ASP.net Project

Posted on 2013-05-14
11
Medium Priority
?
236 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
  • 7
  • 3
11 Comments
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 1125 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 1125 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1125 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 375 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

916 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