#freeze
閲覧総計:&counter();  (本日:&counter(today);  昨日:&counter(yesterday);)

 データベースにデータを新規登録した「作成日時」や、データの内容を編集更新した
「更新日時」を記録に残しておく事は、データ管理上とても有用である。
 MS AccessをDBとし、GridViewでデータの「作成日時」と「更新日時」を自動で登録
する方法を確認したので記録に残しておく。  09/12/01

【稼働画面】
#ref(AutoDate01.JPG)

【方法】
「作成日時」の自動登録

 <script runat="server">
      Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
         If e.CommandName = "Insert" Then
             AccessDataSource1.InsertParameters.Clear()
             For Each key As String In Request.Form.AllKeys
                 If key.Contains("$TextBox2") Then
                     AccessDataSource1.InsertParameters.Add(New ControlParameter("名前", TypeCode.String, key, "Text"))
                 End If
             Next
             AccessDataSource1.Insert()
         End If
 
     End Sub
 </script>
 
 <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data\MyDB.mdb"
 
     InsertCommand="INSERT INTO `名簿2` (`名前`, `作成日時`, `更新日時`) VALUES (?, Now(), Now())"
 
     <InsertParameters>
         <asp:Parameter Name="名前" Type="String" />
         <asp:Parameter Name="作成日時" Type="DateTime" />
         <asp:Parameter Name="更新日時" Type="DateTime" />
     </InsertParameters>
 
 </asp:AccessDataSource>

「更新日時」の自動登録
#ref(AutoDate02.JPG)

 <asp:TemplateField HeaderText="更新日時" SortExpression="更新日時">
     <ItemTemplate>
         <asp:Label ID="Label1" runat="server" Text='<%# Eval("更新日時", "{0: yy/MM/dd HH:mm}") %>'></asp:Label>
     </ItemTemplate>
 </asp:TemplateField>
 
 <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data\MyDB.mdb"
 
     UpdateCommand="UPDATE `名簿2` SET `名前` = ?, `作成日時` = ?, `更新日時` = Now() WHERE `ID` = ?">
 
     <UpdateParameters>
         <asp:Parameter Name="名前" Type="String" />
         <asp:Parameter Name="作成日時" Type="DateTime" />
         <asp:Parameter Name="ID" Type="Int32" />
     </UpdateParameters>
     
 </asp:AccessDataSource>

【機能】データの新規挿入を行うと「作成日時」と「更新日時」に現在の日時が自動
登録される。
 GridViewの「編集」機能でデータの「更新」を行うと「更新日時」に現在の日時が
自動登録される。

【稼働画面】
#ref(AutoDate01.JPG)

Accessデータベース名:MyDB.mdb
テーブル名:名簿2
|~フィールド名|~データ型|~フィールドサイズ|
|ID (主キー)|オートナンバー型|長整数型|
|名前|テキスト型|50|
|作成日時|日付/時刻型||
|更新日時|日付/時刻型||

※VWD2005、ASP.NET2.0ではAccess2007のDBファイル形式(*.accdb)は利用できない。
DBファイルは「Acces2002-2003形式(*.mdb)」で保存してASP.NETで利用する。

開発環境:VWD2005 + Access2003
サーバ:ASP.NET2.0 + Access2003

【AutoDate01.aspx】
 <%@ Page Language="VB" %>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 <script runat="server">
 
     Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
         If e.CommandName = "Insert" Then
             AccessDataSource1.InsertParameters.Clear()
             For Each key As String In Request.Form.AllKeys
                 If key.Contains("$TextBox2") Then
                     AccessDataSource1.InsertParameters.Add(New ControlParameter("名前", TypeCode.String, key, "Text"))
                 End If
             Next
             AccessDataSource1.Insert()
         End If
 
     End Sub
 </script>
 
 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
     <title>データの作成日時、更新日時を自動登録する</title>
 </head>
 <body>
     <form id="form1" runat="server">
     <div>
         データの作成日時、更新日時を自動登録する 09/11/30<br />
         &nbsp;<br />
         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
             DataSourceID="AccessDataSource1" EmptyDataText="表示するデータ レコードがありません。" ShowFooter="True" OnRowCommand="GridView1_RowCommand">
             <Columns>
                 <asp:TemplateField ShowHeader="False">
                     <EditItemTemplate>
                         <asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Update"
                             Text="更新" />&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"
                                 CommandName="Cancel" Text="キャンセル" />
                     </EditItemTemplate>
                     <FooterTemplate>
                         <asp:Button ID="Button3" runat="server" CommandName="Insert" Text="挿入" />
                     </FooterTemplate>
                     <ItemTemplate>
                         <asp:Button ID="Button1" runat="server" CausesValidation="False" CommandName="Edit"
                             Text="編集" />
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
                 <asp:TemplateField HeaderText="名前" SortExpression="名前">
                     <EditItemTemplate>
                         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("名前") %>'></asp:TextBox>
                     </EditItemTemplate>
                     <FooterTemplate>
                         <asp:TextBox ID="TextBox2" runat="server" Width="60px"></asp:TextBox>
                     </FooterTemplate>
                     <ItemTemplate>
                         <asp:Label ID="Label2" runat="server" Text='<%# Bind("名前") %>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:BoundField DataField="作成日時" DataFormatString="{0: yy/MM/dd HH:mm}" HeaderText="作成日時"
                     SortExpression="作成日時" />
                 <asp:TemplateField HeaderText="更新日時" SortExpression="更新日時">
                     <ItemTemplate>
                         <asp:Label ID="Label1" runat="server" Text='<%# Eval("更新日時", "{0: yy/MM/dd HH:mm}") %>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
             </Columns>
         </asp:GridView>
         <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data\MyDB.mdb"
             DeleteCommand="DELETE FROM `名簿2` WHERE `ID` = ?"
             InsertCommand="INSERT INTO `名簿2` (`名前`, `作成日時`, `更新日時`) VALUES (?, Now(), Now())"
             SelectCommand="SELECT `ID`, `名前`, `作成日時`, `更新日時` FROM `名簿2`"
             UpdateCommand="UPDATE `名簿2` SET `名前` = ?, `作成日時` = ?, `更新日時` = Now() WHERE `ID` = ?">
             <DeleteParameters>
                 <asp:Parameter Name="ID" Type="Int32" />
             </DeleteParameters>
             <InsertParameters>
                 <asp:Parameter Name="名前" Type="String" />
                 <asp:Parameter Name="作成日時" Type="DateTime" />
                 <asp:Parameter Name="更新日時" Type="DateTime" />
             </InsertParameters>
             <UpdateParameters>
                 <asp:Parameter Name="名前" Type="String" />
                 <asp:Parameter Name="作成日時" Type="DateTime" />
                 <asp:Parameter Name="ID" Type="Int32" />
             </UpdateParameters>
         </asp:AccessDataSource>
         <br />
     
     </div>
     </form>
 </body>
 </html>


【参考にしたページ】
  該当なし
- 1 -- [[1]] &new{2012-01-25 (水) 13:33:54};
- 1 -- [[1]] &new{2012-01-25 (水) 13:33:56};
- 1 -- [[-1']] &new{2012-01-25 (水) 13:33:58};
-- 1' -- [[1]] &new{2012-01-25 (水) 13:33:59};
- 1 -- [[1]] &new{2012-01-25 (水) 13:34:00};
- 1 -- [[1]] &new{2012-02-20 (月) 08:44:07};
- 1 -- [[1]] &new{2012-02-20 (月) 08:44:09};
- 1 -- [[-1']] &new{2012-02-20 (月) 08:44:10};
-- 1' -- [[1]] &new{2012-02-20 (月) 08:44:12};
- 1 -- [[1]] &new{2012-02-20 (月) 08:44:13};
- 1 -- [[1]] &new{2012-03-12 (月) 18:39:27};
- 1 -- [[1]] &new{2012-03-12 (月) 18:39:30};
- 1 -- [[-1']] &new{2012-03-12 (月) 18:39:31};
-- 1' -- [[1]] &new{2012-03-12 (月) 18:39:32};
- 1 -- [[1]] &new{2012-03-12 (月) 18:39:33};
- 1 -- [[1]] &new{2012-03-13 (火) 15:18:07};
- 1 -- [[1]] &new{2012-03-13 (火) 15:18:10};
- 1 -- [[-1']] &new{2012-03-13 (火) 15:18:11};
-- 1' -- [[1]] &new{2012-03-13 (火) 15:18:12};
- 1 -- [[1]] &new{2012-03-13 (火) 15:18:13};
- 1 -- [[1]] &new{2012-03-28 (水) 21:39:41};
- 1 -- [[1]] &new{2012-03-28 (水) 21:39:45};
- 1 -- [[-1']] &new{2012-03-28 (水) 21:39:46};
-- 1' -- [[1]] &new{2012-03-28 (水) 21:39:47};
- 1 -- [[1]] &new{2012-03-28 (水) 21:39:48};
- fdさd -- [[gdさ]] &new{2012-04-19 (木) 16:21:08};
- 1 -- [[1]] &new{2012-05-10 (木) 02:17:06};
- 1 -- [[1]] &new{2012-05-10 (木) 02:17:09};
- 1 -- [[-1']] &new{2012-05-10 (木) 02:17:10};
-- 1' -- [[1]] &new{2012-05-10 (木) 02:17:11};
- 1 -- [[1]] &new{2012-05-10 (木) 02:17:12};
- 1 -- [[1]] &new{2012-05-16 (水) 09:22:02};
- 1 -- [[1]] &new{2012-05-16 (水) 09:22:06};
- 1 -- [[-1']] &new{2012-05-16 (水) 09:22:07};
-- 1' -- [[1]] &new{2012-05-16 (水) 09:22:08};
- 1 -- [[1]] &new{2012-05-16 (水) 09:22:09};
- 1 -- [[1]] &new{2012-05-17 (木) 06:51:25};
- 1 -- [[1]] &new{2012-05-17 (木) 06:51:30};
- 1 -- [[-1']] &new{2012-05-17 (木) 06:51:31};
-- 1' -- [[1]] &new{2012-05-17 (木) 06:51:32};
- 1 -- [[1]] &new{2012-05-17 (木) 06:51:34};
- 1 -- [[1]] &new{2012-05-19 (土) 22:00:35};
- 1 -- [[1]] &new{2012-05-19 (土) 22:00:38};
- 1 -- [[-1']] &new{2012-05-19 (土) 22:00:40};
-- 1' -- [[1]] &new{2012-05-19 (土) 22:00:41};
- 1 -- [[1]] &new{2012-05-19 (土) 22:00:42};
- 1 -- [[1]] &new{2012-05-24 (木) 14:11:39};
- 1 -- [[1]] &new{2012-05-24 (木) 14:11:45};
- 1 -- [[-1']] &new{2012-05-24 (木) 14:11:46};
-- 1' -- [[1]] &new{2012-05-24 (木) 14:11:47};
- 1 -- [[1]] &new{2012-05-24 (木) 14:11:48};
- 1 -- [[1]] &new{2012-05-28 (月) 07:21:48};
- 1 -- [[1]] &new{2012-05-28 (月) 07:21:51};
- 1 -- [[-1']] &new{2012-05-28 (月) 07:21:52};
-- 1' -- [[1]] &new{2012-05-28 (月) 07:21:53};
- 1 -- [[1]] &new{2012-05-28 (月) 07:21:54};
- 1 -- [[1]] &new{2012-06-12 (火) 21:35:41};
- 1 -- [[1]] &new{2012-06-12 (火) 21:35:44};
- 1 -- [[-1']] &new{2012-06-12 (火) 21:35:46};
-- 1' -- [[1]] &new{2012-06-12 (火) 21:35:47};
- 1 -- [[1]] &new{2012-06-12 (火) 21:35:48};
- 1 -- [[1]] &new{2012-06-13 (水) 01:36:04};
- 1 -- [[1]] &new{2012-06-13 (水) 01:36:08};
- 1 -- [[-1']] &new{2012-06-13 (水) 01:36:09};
-- 1' -- [[1]] &new{2012-06-13 (水) 01:36:10};
- 1 -- [[1]] &new{2012-06-13 (水) 01:36:11};
- 1 -- [[1]] &new{2012-06-15 (金) 02:44:20};
- 1 -- [[1]] &new{2012-06-15 (金) 02:44:24};
- 1 -- [[-1']] &new{2012-06-15 (金) 02:44:25};
-- 1' -- [[1]] &new{2012-06-15 (金) 02:44:26};
- 1 -- [[1]] &new{2012-06-15 (金) 02:44:28};
- 1 -- [[1]] &new{2012-06-25 (月) 21:20:21};
- 1 -- [[1]] &new{2012-06-25 (月) 21:20:25};
- 1 -- [[-1']] &new{2012-06-25 (月) 21:20:26};
-- 1' -- [[1]] &new{2012-06-25 (月) 21:20:27};
- 1 -- [[1]] &new{2012-06-25 (月) 21:20:28};
- 1 -- [[1]] &new{2012-06-29 (金) 09:54:42};
- 1 -- [[1]] &new{2012-06-29 (金) 09:54:46};
- 1 -- [[-1']] &new{2012-06-29 (金) 09:54:47};
-- 1' -- [[1]] &new{2012-06-29 (金) 09:54:48};
- 1 -- [[1]] &new{2012-06-29 (金) 09:54:50};
- 1 -- [[1]] &new{2012-06-29 (金) 12:17:10};
- 1 -- [[1]] &new{2012-06-29 (金) 12:17:13};
- 1 -- [[-1']] &new{2012-06-29 (金) 12:17:15};
-- 1' -- [[1]] &new{2012-06-29 (金) 12:17:16};
- 1 -- [[1]] &new{2012-06-29 (金) 12:17:17};
- 1 -- [[1]] &new{2014-08-13 (水) 04:52:02};
- 1 -- [[1]] &new{2014-08-13 (水) 04:52:21};
- 1 -- [[-1']] &new{2014-08-13 (水) 04:52:23};
-- 1' -- [[1]] &new{2014-08-13 (水) 04:52:25};
- 1 -- [[1]] &new{2014-08-13 (水) 04:52:26};
- http://www.coachcanadaoutlet.ca http://www.prada-outlet.us http://www.louboutinfemme-pascher.fr http://www.ralphlaurensale.eu.com http://www.jordan3.net http://www.louisvuitton-handbags.com.co http://www.poloralphlaurenhome.net http://www.abercrombie.net.co http://www.holister.name http://www.christian-louboutinoutlet.org http://www.rolexwatchesoutlet.us http://www.abercrombieandfitch.net.co http://www.coachoutletstoreonline.us.org http://www.katespade-outlet.us.com http://www.chanelhandbags.in.net http://www.longchamp-outlet.name http://www.jordan4.net http://www.raybans.name http://www.michaelkorsoutletus.eu.com http://www.louisvuittonoutlets.name http://www.airmax-nike.me.uk http://www.hollisterinc.name http://www.cheaptoms.us http://www.fendi.us.com http://www.michaelkorsoutlet-mk.eu.com http://www.hollister-clothing.net http://www.juicy-couture.us http://www.hollisterclothing.us http://www.pandorajewelry.net.co http://timberlandboots.hugeoff.net http://www.hollisterkids.net http://www.abercrombiestores.net http://www.louisvuittonoutlet-inc.us http://oakley.hugeoff.net http://www.ralph-lauren.net.co http://www.louis-vuitton.us.org http://www.louis--vuitton.us http://lululemon.suleymanaltun.com http://www.marc--jacobs.com http://www.airjordan-pascher.fr http://www.abercrombie.in.net http://www.louisvuitton-lvoutlet.me http://www.guccishoes.us.com http://www.coachoutlet.net.so http://www.michaelkorshandbags.com.so http://www.tory-burchoutlet.in.net http://www.rayban-sunglasses.com.co http://www.retrojordans.name http://www.concords11.com http://www.cheapjordansshoes.in.net http://www.p90xworkouts.us http://truereligion.officialbid.net http://www.guccioutlet.net.co http://burberry.stores.net.co http://www.michaelkorshandbags.eu.com http://www.edhardyclothing.in.net http://www.michaelkorsoutletonlinee.in.net http://www.chiflatiron.com.co http://www.oakleysunglassessale.in.net http://burberryoutlet.officialstore.com.co http://www.coachoutletstoreonline.eu.com http://www.gucci.net.co http://www.abercrombieandfitch.cc http://www.coach-outlet.us.com http://www.michaelkorsoutlet.net.so http://www.cocochaneluk.co.uk http://www.louisvuitton-outlet.us.com http://www.louisvuittonhandbags.net.co http://www.ralph-lauren-outlet.co http://www.louisvuittonuk.me.uk http://www.coach-outlet.us.org http://www.ray-bansunglasses.name http://www.louis-vuitton.net.co http://www.adidasshoes.name http://www.louis-vuittonoutlet.us.org http://www.true-religion-outlet.us.com http://www.michaelkorsonlineoutlet.in.net http://www.jordan13.org http://www.abercrombieoutlet.name http://www.kobeshoes.org http://www.hollister-co.net http://www.holisterclothingstore.com http://www.michaelkorsoutlet.com.so http://www.fitflops.org http://www.kobebryantshoes.name http://www.oakley-sunglasses.net.co http://www.kevindurantshoes.name http://www.pradauk.co.uk http://www.michaelkorsukpurse.co.uk http://www.gucci-outlet.org http://burberry.bidinc.org http://www.oakleysunglassescheap.name http://www.oakleysunglasses.us.com http://michaelkors.officialstore.com.co http://www.cheapsoccershoes.in.net http://www.coachoutlet-storeonline.in.net http://www.todsshoes.us http://www.jordan8.net http://www.christianlouboutinoutlet.org http://www.raybanglasses.me.uk http://www.abercrombieoutlet.us.com http://www.montblanc-pens.name http://www.christianlouboutin.name http://www.oakleysunglasses-wholesale.name http://www.raybansunglassesoutlet.name http://www.christianlouboutin-shoes.info http://www.raybansunglass.net.co http://www.ray-banoutlet.name http://www.michaelkors--outlet.in.net http://www.truereligion.eu.com http://www.coach-factoryoutlet.com.co http://www.outlet-celine.com http://www.christianlouboutinoutlet.com.co http://www.oakleysunglasses-outlet.name http://www.fitflop-shoes.us http://www.soccer-jerseys.us.com http://www.michaelkors.com.so http://www.todsoutlet.name http://www.cheap--nfljerseys.us.com http://www.abercrombie-fitch.cc http://www.tory-burch-outlet.name http://www.redchristianlouboutin.com http://www.hermes-birkin.us http://www.michaelkors-mkoutlet.in.net http://timberland.officialfree.net http://www.chanel-handbags.net.co http://www.christianlouboutinsale.name http://www.jordan11s.name http://www.pandorajewelry.name http://burberryoutlet.newestsite.net http://www.louisvuitton.us.com http://www.montblanc.com.co http://www.cheap-jordans.us.com http://www.toms--shoes.com http://beatsbydrdre.outletoff.net http://www.cheapjerseys-wholesale.us.com http://www.christianlouboutinsale.biz http://www.michael-korsoutletonline.eu.com http://www.abercrombiestore.org http://www.rayban-sunglasses.eu.com http://www.louis-vuittonhandbags.name http://www.oakley-sunglasses.com.co http://timberlandboots.dealsinc.net http://www.nike-airmax.me.uk http://www.jordan11.name http://www.saclongchamp--pascher.fr http://www.michaelkors-outlet.com.co http://www.gucci-outlet.name http://michaelkors.aphidsymposium.org http://www.cheaprolexwatches.name http://www.chanelbags.com.co http://www.toms-shoes.cc http://www.insanityworkout.com.co http://www.louisvuittonoutlet.net.co http://www.coachfactoryoutlet.com.so http://www.jordanretro.name http://coachoutlet.officialinc.net http://www.toms-outlet.com.co http://www.poloralph-lauren.net.co http://toryburchoutlet.stores.net.co http://www.michaelkorsbag.org.uk http://www.coachoutlet-factory.com.co http://www.dior-handbags.us http://chanelhandbags.newstore.com.co http://www.abercrombiekids.name http://www.coachfactoryoutletonline.eu.com http://www.jordan11concord.org http://www.abercrombie-fitch.com.co http://www.michaelkorsoutletclearance.in.net http://www.jordanconcords.net http://www.gucci-outlet.net.co http://www.lebronjames-shoes.net http://www.adidaswings.name http://www.celine-outlet.us http://www.hollisterclothing.info http://www.ghdhairstraighteners.com.co http://www.lebronjames-shoes.name http://www.oakleysunglasses-sale.in.net http://www.longchamphandbags.com.co http://truereligion.onlineinc.net.co http://www.hollisteroutlet.name http://www.katespade-handbags.eu.com http://www.ray-ban-sunglasses.org.uk http://www.jordan6.net -- [[2015711yuanyuan]] &new{2015-07-10 (金) 22:07:37};

#comment_nospam
- 1 -- [[1]] &new{2012-06-29 (金) 12:17:12};
- 1 -- [[1]] &new{2012-06-29 (金) 09:54:45};
- 1 -- [[1]] &new{2012-06-25 (月) 21:20:24};
- 1 -- [[1]] &new{2012-06-15 (金) 02:44:22};
- 1 -- [[1]] &new{2012-06-13 (水) 01:36:07};
- 1 -- [[1]] &new{2012-06-12 (火) 21:35:43};
- 1 -- [[1]] &new{2012-05-28 (月) 07:21:49};
- 1 -- [[1]] &new{2012-05-24 (木) 14:11:43};
- 1 -- [[1]] &new{2012-05-19 (土) 22:00:37};
- 1 -- [[1]] &new{2012-05-17 (木) 06:51:29};
- 1 -- [[1]] &new{2012-05-16 (水) 09:22:04};
- 1 -- [[1]] &new{2012-05-10 (木) 02:17:08};
- 1 -- [[1]] &new{2012-03-28 (水) 21:39:43};
- 1 -- [[1]] &new{2012-03-13 (火) 15:18:09};
- 1 -- [[1]] &new{2012-03-12 (月) 18:39:29};
- 1 -- [[1]] &new{2012-02-20 (月) 08:44:08};
- 1 -- [[1]] &new{2012-01-25 (水) 13:33:55};
#vote(参考になった[5],ふつう[0],参考にならなかった[0])


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS