SqlDataSourceView.UpdateCommand プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlDataSourceView.UpdateCommand プロパティの意味・解説 

SqlDataSourceView.UpdateCommand プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

基になるデータベース内のデータを更新するために SqlDataSourceView オブジェクトが使用する SQL 文字列を取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As SqlDataSourceView
Dim value As String

value = instance.UpdateCommand

instance.UpdateCommand = value
public string UpdateCommand { get;
 set; }
public:
property String^ UpdateCommand {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_UpdateCommand ()

/** @property */
public void set_UpdateCommand (String value)
public function get UpdateCommand
 () : String

public function set UpdateCommand
 (value : String)

プロパティ値
データを更新するために SqlDataSourceView が使用する SQL 文字列。

解説解説

異なるデータベース製品では異なる種類の SQL が使用されるため、SQL 文字列の構文は、現在使用されている ADO.NET プロバイダによって異なります。このプロバイダは、ProviderName プロパティによって示されます。SQL 文字列がパラメータ化されたクエリまたはコマンドである場合、パラメータのプレースホルダは、使用されている ADO.NET プロバイダに依存します。たとえば、プロバイダが SqlDataSource クラスの既定のプロバイダである System.Data.SqlClient の場合、パラメータのプレースホルダは '@parameterName' です。ただし、プロバイダが System.Data.Odbc または System.Data.OleDb に設定されている場合、パラメータのプレースホルダは '?' となります。パラメータ化された SQL クエリとコマンドの詳細については、「SqlDataSource コントロールにおけるパラメータの使用」を参照してください。

データ ソースがストアド プロシージャをサポートしている場合、UpdateCommand プロパティには、SQL 文字列またはストアド プロシージャの名前を指定できます。

UpdateCommand プロパティの値はビューステートに格納されます。

使用例使用例

このセクションには、2 つのコード例が含まれています。SqlDataSource コントロールの UpdateCommand プロパティを設定し、GridView コントロールを使用して Microsoft SQL Server データベース内のデータを更新する方法を最初のコード例に示します。GridView コントロールを使用して ODBC データベース内のデータを更新する方法を 2 番目のコード例に示します。

SqlDataSource コントロールの UpdateCommand プロパティを設定し、GridView コントロールを使用して SQL Server データベース内のデータを更新する方法を次のコード例に示します。GridView コントロールは、BoundField オブジェクトからパラメータを推測して自動的に UpdateParameters コレクションを設定し、編集可能な GridView コントロールの [更新] リンクを選択したときに、Update メソッドを呼び出します。この例には、レコードが更新され、電子メール メッセージ通知が送信された後の後処理も含まれています。

<%@Page  Language="VB" %>
<%@Import Namespace="System.Web.Mail"
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">

 Sub OnDSUpdatedHandler(ByVal source As
 Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.AffectedRows > 0 Then
        ' Perform any additional processing, 
        ' such as setting a status label after the operation.      
  
        Label1.Text = Request.LogonUserIdentity.Name & _
            " changed user information successfully!"
    Else 
        Label1.Text = "No data updated!"
    End If
 End Sub 'OnDSUpdatedHandler
</SCRIPT>

<HTML>
  <BODY>
    <FORM runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title
 FROM Employees"
          UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title
 WHERE EmployeeID=@EmployeeID"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name"
 DataField="FirstName" />
              <asp:BoundField HeaderText="Last Name"
 DataField="LastName" />
              <asp:BoundField HeaderText="Title"
 DataField="Title" />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </FORM>
  </BODY>
</HTML>
<%@Page  Language="C#" %>
<%@Import Namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
 private void OnDSUpdatedHandler(Object source,
 SqlDataSourceStatusEventArgs e) {
    if (e.AffectedRows > 0) {
        // Perform any additional processing, 
        // such as setting a status label after the operation.
        Label1.Text = Request.LogonUserIdentity.Name +
            " changed user information successfully!";    
    }
    else {
        Label1.Text = "No data updated!";
    }
 }
</SCRIPT>

<HTML>
  <BODY>
    <FORM runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title
 WHERE EmployeeID=@EmployeeID"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName"
 />
              <asp:BoundField HeaderText="Last Name" DataField="LastName"
 />
              <asp:BoundField HeaderText="Title" DataField="Title"
 />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </FORM>
  </BODY>
</HTML>
<%@Page  Language="VJ#" %>
<%@Import Namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
    private void OnDSUpdatedHandler(Object
 source, SqlDataSourceStatusEventArgs e)
    {
        if (e.get_AffectedRows() > 0) {
            // Perform any additional processing, such as sending an
 e-mail notification.
            Label1.set_Text(get_Request().get_LogonUserIdentity().get_Name() +
               " changed user information successfully!");    
        }
        else {
            Label1.set_Text("No data updated!");
        }
    } //OnDSUpdatedHandler
</SCRIPT>

<HTML>
  <BODY>
    <FORM runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title
 WHERE EmployeeID=@EmployeeID"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <Columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName"
 />
              <asp:BoundField HeaderText="Last Name" DataField="LastName"
 />
              <asp:BoundField HeaderText="Title" DataField="Title"
 />
          </Columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </FORM>
  </BODY>
</HTML>

GridView コントロールを使用して ODBC データベース内のデータを更新する方法を次のコード例に示します。これは機能的には前のコード例と同じです。ProviderName プロパティは、ODBC の ADO.NET プロバイダである System.Data.Odbc に設定され、ConnectionString プロパティは、ODBC データ ソース名 (DSN) に設定されます。

<%@Page  Language="VB" %>
<%@Import Namespace="System.Web.Mail"
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">

 Sub OnDSUpdatedHandler(ByVal source As
 Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.AffectedRows > 0 Then
        ' Perform any additional processing, such as setting a status
 label.
        Label1.Text = Request.LogonUserIdentity.Name & _
            " changed user information sucessfully!"
    Else
        Label1.Text = "No data updated!"
    End If
 End Sub 'OnDSUpdatedHandler

</SCRIPT>


<HTML>
  <BODY>
    <!-- This example uses a Northwind database that is hosted
 by an ODBC-compliant
         database. To run this sample, create an ODBC DSN to
 any database that hosts
         the Northwind database, including Microsoft SQL Server or
 Microsoft Access,
         change the name of the DSN in the
 ConnectionString, and view the page.
    -->
    <FORM runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          DataSourceMode="DataSet"
          ConnectionString="dsn=myodbc3dsn;"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title
 FROM Employees"
          UpdateCommand="Update Employees SET FirstName=?,LastName=?,Title=?
 WHERE EmployeeID=?"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name"
 DataField="FirstName" />
              <asp:BoundField HeaderText="Last Name"
 DataField="LastName" />
              <asp:BoundField HeaderText="Title"
 DataField="Title" />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </FORM>
  </BODY>
</HTML>
<%@Page  Language="C#" %>
<%@Import Namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">

 private void OnDSUpdatedHandler(Object source,
 SqlDataSourceStatusEventArgs e) {
    if (e.AffectedRows > 0) {
        // Perform any additional processing, such as sending an e-mail
 notification.
        Label1.Text = Request.LogonUserIdentity.Name +
            " changed user information sucessfully!";
    }
    else {
        Label1.Text = "No data updated!";
    }
 }
</SCRIPT>

<HTML>
  <BODY>
    <!-- This example uses a Northwind database that is hosted by an ODBC-compliant
         database. To run this sample, create an ODBC DSN to any
 database that hosts
         the Northwind database, including Microsoft SQL Server or Microsoft Access
,
         change the name of the DSN in the ConnectionString, and
 view the page.
    -->
    <FORM runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          DataSourceMode="DataSet"
          ConnectionString="dsn=myodbc3dsn;"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=?,LastName=?,Title=?
 WHERE EmployeeID=?"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName"
 />
              <asp:BoundField HeaderText="Last Name" DataField="LastName"
 />
              <asp:BoundField HeaderText="Title" DataField="Title"
 />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </FORM>
  </BODY>
</HTML>
<%@Page  Language="VJ#" %>
<%@Import Namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
    private void OnDSUpdatedHandler(Object
 source, SqlDataSourceStatusEventArgs e)
    {
        if (e.get_AffectedRows() > 0) {
            // Perform any additional processing, such as sending an
 e-mail notification.
            Label1.set_Text(get_Request().get_LogonUserIdentity().get_Name() +
                " changed user information successfully!");
        }
        else {
            Label1.set_Text("No data updated!");
        }
    } //OnDSUpdatedHandler
</SCRIPT>

<HTML>
  <BODY>
    <!-- This example uses a Northwind database that is hosted by an ODBC-compliant
         database. To run this sample, create an ODBC DSN to any
 database that hosts
         the Northwind database, including Microsoft SQL Server or Microsoft Access
,
         change the name of the DSN in the ConnectionString, and
 view the page.
    -->
    <FORM runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          DataSourceMode="DataSet"
          ConnectionString="dsn=myodbc3dsn;"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=?,LastName=?,Title=?
 WHERE EmployeeID=?"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <Columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName"
 />
              <asp:BoundField HeaderText="Last Name" DataField="LastName"
 />
              <asp:BoundField HeaderText="Title" DataField="Title"
 />
          </Columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </FORM>
  </BODY>
</HTML>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlDataSourceView クラス
SqlDataSourceView メンバ
System.Web.UI.WebControls 名前空間
ExecuteUpdate
Update
UpdateParameters



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「SqlDataSourceView.UpdateCommand プロパティ」の関連用語

SqlDataSourceView.UpdateCommand プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlDataSourceView.UpdateCommand プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS