0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ASP.NET(Web) GridView/SqlDataSourceでバインド変数エラー発生

Posted at
filename.aspx
【開発環境】
OS :Windows7
アプリ:VS2010(ASP.NET C# Web)
DB :Oracle 12c

【やりたいこと】 
1.GridView/SqlDataSourceコントロールを利用してOracleデータベースの抽出データを表に表示する。 
2.GridView上の追加した編集(Update)、削除(Delete)機能を使ってデータベースを更新したい。 

【教えて頂きたいこと】 
削除(Delete)機能では『ORA-01006: バインド変数がありません』が発生。
編集(Update)機能では『ORA-01008: バインドされていない変数があります』が発生。

なお、selectは正常動作してGridViewに表示できています。

いろいろなサイトで事例などを確認して、同じように記述しているつもりなのですが、
上記エラー解除できず、DB更新できません。


拙い説明で申し訳ございませんが、お教え頂ける様、宜しくお願い致します。 


以下に本処理記述しているaspxファイルの抜粋を記載します。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFrmModify.aspx.cs" Inherits="WebAppAAA.WebFrmModify" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

~中略~
        <asp:GridView ID="GridView1" runat="server" 
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" 
            DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#DEDFDE" 
            BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" 
            GridLines="Vertical" onprerender="GridView1_PreRender">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="更新"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="キャンセル"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Edit" Text="編集"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text="削除" OnClientClick="return confirm('削除しても本当によろしいですか?');"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="年月日" HeaderText="年月日" SortExpression="年月日" 
                    DataFormatString="{0:d}" />
                <asp:TemplateField HeaderText="記録" SortExpression="記録">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("記録") %>' 
                            MaxLength="50"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("記録") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="備考" SortExpression="備考">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("備考") %>' 
                            MaxLength="100" Height="60px" TextMode="MultiLine" Width="400px"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("備考") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="管理部門コード" SortExpression="管理部門コード">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList12" runat="server" 
                            DataSourceID="SqlDataSource1" DataTextField="設置場所" DataValueField="設置場所ID" 
                            SelectedValue='<%# Bind("管理部門コード") %>'
                            AppendDataBoundItems="True">
                            <asp:ListItem Value=""> </asp:ListItem>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                            providerName="Oracle.ManagedDataAccess.Client"
                            ConnectionString="<%$ ConnectionStrings:SETSUBISVDBConnectionString %>"
                            SelectCommand="SELECT 設置場所ID, 設置場所 FROM T_設置場所 ORDER BY 設置場所">
                        </asp:SqlDataSource>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("管理部門コード") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="担当" SortExpression="担当">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("担当") %>' 
                            MaxLength="50" TextMode="MultiLine" Height="36px" Width="220px"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("担当") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#CCCC99" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FBFBF2" />
            <SortedAscendingHeaderStyle BackColor="#848384" />
            <SortedDescendingCellStyle BackColor="#EAEAD3" />
            <SortedDescendingHeaderStyle BackColor="#575357" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            providerName="Oracle.ManagedDataAccess.Client"
            ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
            DeleteCommand="DELETE FROM T_点検記録年月 WHERE ID = :original_ID" 
            SelectCommand="SELECT ID, 年月日, 管理部門コード, 記録, 備考, 担当 FROM T_点検記録年月 WHERE (登録番号 = :登録番号) ORDER BY 年月日 DESC, ID DESC"
            UpdateCommand="UPDATE T_点検記録年月 SET 年月日 = :年月日, 管理部門コード = :管理部門コード, 記録 = :記録, 備考 = :備考, 担当 = :担当 WHERE ID = :original_ID AND ((年月日 = :original_年月日) OR (年月日 IS NULL AND :original_年月日 IS NULL)) AND ((管理部門コード = :original_管理部門コード) OR (管理部門コード IS NULL AND :original_管理部門コード IS NULL)) AND ((記録 = :original_記録) OR (記録 IS NULL AND :original_記録 IS NULL)) AND ((備考 = :original_備考) OR (備考 IS NULL AND :original_備考 IS NULL)) AND ((担当 = :original_担当) OR (担当 IS NULL AND :original_担当 IS NULL))" 
            OldValuesParameterFormatString="original_{0}" 
            ConflictDetection="CompareAllValues">
            <DeleteParameters>
                <asp:Parameter Name="original_ID" Type="Int32" />
            </DeleteParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList11" Name="登録番号" 
                    PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="年月日" Type="DateTime" />
                <asp:Parameter Name="管理部門コード" Type="Double" />
                <asp:Parameter Name="記録" Type="String" />
                <asp:Parameter Name="備考" Type="String" />
                <asp:Parameter Name="担当" Type="String" />
                <asp:Parameter Name="original_ID" Type="Int32" />
                <asp:Parameter Name="original_年月日" Type="DateTime" />
                <asp:Parameter Name="original_管理部門コード" Type="Double" />
                <asp:Parameter Name="original_記録" Type="String" />
                <asp:Parameter Name="original_備考" Type="String" />
                <asp:Parameter Name="original_担当" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?