Solved

Simple updates using grid and sql data source

Posted on 2010-09-02
3
236 Views
Last Modified: 2012-05-10
The code window shows an sql data source and a grid.
It also has the stored procedure used by the update command.

When I try and update a column it either blanks out all the columns I've not chosen to update or gives me an error message saying:
@original_Code is not a parameter for procedure UpdateAllEq.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT * FROM [AllEq]" UpdateCommand="UpdateAllEq" OldValuesParameterFormatString="original_{0}" UpdateCommandType="StoredProcedure">
                <DeleteParameters>
                    <asp:Parameter Name="original_Code" Type="String" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Code" Type="String" />
                    <asp:Parameter Name="NAME" Type="String" />
                    <asp:Parameter Name="GEOGN" Type="String" />
                    <asp:Parameter Name="Cov" Type="String" />
                    <asp:Parameter Name="TIME" Type="String" />
                </UpdateParameters>
            </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="Code" DataSourceID="SqlDataSource1"
            PageSize="20">
            <PagerSettings Mode="NextPreviousFirstLast" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="Code" HeaderText="Code" ReadOnly="True" SortExpression="Code" />
                <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
                <asp:BoundField DataField="GEOGN" HeaderText="GEOGN" SortExpression="GEOGN" />
                <asp:BoundField DataField="COV" HeaderText="COV" SortExpression="COV" />
                <asp:BoundField DataField="TIME" HeaderText="TIME" SortExpression="TIME" />
            </Columns>
        </asp:GridView>
        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
            DataKeyNames="Code" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
            <Fields>
                <asp:BoundField DataField="Code" HeaderText="Code" ReadOnly="True" SortExpression="Code" />
                <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
                <asp:BoundField DataField="GEOGN" HeaderText="GEOGN" SortExpression="GEOGN" />
                <asp:BoundField DataField="COV" HeaderText="COV" SortExpression="COV" />
                <asp:BoundField DataField="TIME" HeaderText="TIME" SortExpression="TIME" />
            </Fields>
        </asp:DetailsView>

------------Stored Procedure
ALTER PROCEDURE [dbo].[UpdateAllEq]
(
@Code varchar(6) ,
@Name varchar(255),
@GEOGN varchar(255),
@Cov varchar(255),
@TIME varchar(255))

AS
UPDATE [AllEq] 
SET [NAME] = @NAME, 
[GEOGN] = @GEOGN, 
Cov = @Cov, 
[TIME] = @TIME
WHERE [Code] = @Code

Open in new window

0
Comment
Question by:AlHal2
[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
  • 2
3 Comments
 

Author Comment

by:AlHal2
ID: 33587100
The main thing is that I want to know exactly what SQL was passed to the database.
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 33615245
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT * FROM [AllEq]" UpdateCommand="UpdateAllEq" OldValuesParameterFormatString="original_{0}" <UpdateCommandType="StoredProcedure">
             
                <UpdateParameters>
                    <asp:Parameter Name="Code" Type="String" />
                    <asp:Parameter Name="NAME" Type="String" />
                    <asp:Parameter Name="GEOGN" Type="String" />
                    <asp:Parameter Name="Cov" Type="String" />
                    <asp:Parameter Name="TIME" Type="String" />
                </UpdateParameters>
            </asp:SqlDataSource>

        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="Code" DataSourceID="SqlDataSource1"
            PageSize="20">
            <PagerSettings Mode="NextPreviousFirstLast" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="Code" HeaderText="Code" ReadOnly="True" SortExpression="Code" />
                <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
                <asp:BoundField DataField="GEOGN" HeaderText="GEOGN" SortExpression="GEOGN" />
                <asp:BoundField DataField="COV" HeaderText="COV" SortExpression="COV" />
                <asp:BoundField DataField="TIME" HeaderText="TIME" SortExpression="TIME" />
            </Columns>
        </asp:GridView>
        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
            DataKeyNames="Code" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
            <Fields>
                <asp:BoundField DataField="Code" HeaderText="Code" ReadOnly="True" SortExpression="Code" />
                <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
                <asp:BoundField DataField="GEOGN" HeaderText="GEOGN" SortExpression="GEOGN" />
                <asp:BoundField DataField="COV" HeaderText="COV" SortExpression="COV" />
                <asp:BoundField DataField="TIME" HeaderText="TIME" SortExpression="TIME" />
            </Fields>
        </asp:DetailsView>

0
 

Accepted Solution

by:
AlHal2 earned 0 total points
ID: 33615824
Thanks for this.  Would you be able to make it called stored procedures for the select and update statements?  I don't have any code for inserts or deletes, but could add some if necessary.

Raising points to 300
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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