Link to home
Start Free TrialLog in
Avatar of VBBRett
VBBRett

asked on

Update GridView of ASP.net Project

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

SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBBRett
VBBRett

ASKER

No error message at all, it just doesn't update the grid row
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBBRett

ASKER

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
Avatar of VBBRett

ASKER

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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBBRett

ASKER

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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBBRett

ASKER

I'll still give points or effort, but the answer is what I stated above.
Avatar of VBBRett

ASKER

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.