HTML:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KMSConnectionString %>" InsertCommand="INSERT INTO category(cat001, cat002, objactive, objcreate) VALUES (@cat001,@cat002,@objactive,@objcreate);select @ID=@@Identity " oninserted="SqlDataSource1_Inserted"> <InsertParameters> <asp:ControlParameter Name="cat001" ControlID="cat001" Type="String" /> <asp:Parameter Name="cat002" DefaultValue="Folder" Type="String" /> <asp:ControlParameter Name="objactive" ControlID="objactive" Type="String" /> <asp:Parameter Name="objcreate" Type="String" /> <asp:Parameter Name="ID" Direction="InputOutput" Type="Decimal" /> </InsertParameters> </asp:SqlDataSource>
C#:
protected void SaveButton_Click(object sender, ImageClickEventArgs e) { SqlDataSource1.InsertParameters["objcreate"].DefaultValue = Context.User.Identity.Name; SqlDataSource1.Insert(); } protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e) { string strReturn = e.Command.Parameters["@ID"].Value.ToString(); }
沒有留言:
張貼留言