TSQL Cursor Example 語法
--定義變數
DECLARE @oid varchar(50),
@ono varchar(18),
@s_company nvarchar(50),
@company nvarchar(50),
@sql varchar(max)
--設定變數初始值
SET @oid = ''
SET @ono = ''
SET @s_company= ''
SET @company = ''
SET @sql = ''
--宣告Cursor for 迴圈
DECLARE rma_cursor CURSOR FOR
--SQL指令
SELECT oid,ono,s_company,company FROM dbo.t_RMA_Request
--開始執行 cursor
OPEN rma_cursor
--將第一筆資料放入變數
FETCH NEXT FROM rma_cursor INTO @oid,@ono,@s_company,@company
--檢查是否有讀取到資料; WHILE用來處理迴圈,當為true時則進入迴圈執行
WHILE @@FETCH_STATUS=0
BEGIN --開始
--迴圈內要執行的程序
IF @s_company <> ''
BEGIN
--組合@sql字串變數
SET @sql = @sql + ';' + 'update t_RMA_Request_Item set s_company=''' + @s_company + ''' where opid=''' + @oid + ''''
--實際執行另一段內部SQL指令
UPDATE t_RMA_Request_Item SET s_company=@s_company WHERE opid=@oid
END
ELSE
BEGIN
--組合@sql字串變數
SET @sql = @sql + ';' + 'update t_RMA_Request_Item set s_company=''' + @company + ''' where opid=''' + @oid + ''''
--實際執行另一段內部SQL指令
UPDATE t_RMA_Request_Item SET s_company=@company WHERE opid=@oid
END
--將下一筆資料放入變數
FETCH NEXT FROM rma_cursor INTO @oid,@ono,@s_company,@company
END --結束
--關閉Cursor與參數的關聯
CLOSE rma_cursor
--將Cursor物件從記憶體移除
DEALLOCATE rma_cursor
--列印字串組合結果
PRINT @sql
2013年9月10日 星期二
2013年9月9日 星期一
C# ASP.NET form1 的 Default Button
C# ASP.NET form1 的 Default Button
Sample 1
HTML:
C#:
Sample 2
HTML:
C#:
Sample 1
HTML:
<body> <form id="form1" runat="server" defaultbutton="Button2"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="Button" /><br /> <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" /><br /> </div> </form> </body>
C#:
public partial class Test_tsDefaultButton : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this, typeof(string), "Location", "alert(\"Butonn2\");", true); } }
Sample 2
HTML:
<body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="Button" /><br /> <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" /><br /> </div> </form> </body>
C#:
public partial class Test_tsDefaultButton : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { #region Default Button Button btn = (Button)this.form1.FindControl("Button2"); this.Form.DefaultButton = btn.UniqueID; #endregion #region Default Button UserControl Sample //Button btn = (Button)UserControl1.FindControl("Button2"); //this.form1.DefaultButton = btn.UniqueID; #endregion } protected void Button2_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this, typeof(string), "Location", "alert(\"Butonn2\");", true); } }
訂閱:
文章 (Atom)