#眉標=Ajax #副標=Ajax網頁開發利器(1) #大標=Microsoft Ajax Control Toolkit #作者=文/王寧疆 ==程式1 =========== ================ ==程式2 =========== ================ ==程式3 =========== [WebMethod] string DynamicPopulateMethod(string contextKey) { } ================ ==程式4 =========== ================ ==程式5 ===========
================ ==程式6 =========== ================ ==程式7 =========== [WebMethod] public static string GetQuote(string contextKey) { string strConn = "Data Source=.;Initial Catalog=AdvASPNET;Integrated Security=true"; //資料庫連線資訊 string strSQL = "Select Quote from NewQuotes where ID=@ID"; //查詢格言的SQL敘述 SqlConnection conn = new SqlConnection(strConn); //建立SqlConnection類別的物件 SqlCommand cmd = new SqlCommand(strSQL, conn); //建立SqlCommand類別的物件 cmd.CommandType = CommandType.Text; //指定所要執行的是SQL敘述 Random r = new Random(); //建立Random類別的物件 SqlParameter p = new SqlParameter("@ID", SqlDbType.Int); //建立SqlParameter類別的物件 p.Direction = ParameterDirection.Input; //設定參數的傳遞方向 p.Value = r.Next(1, 11); //產生介於1~10之間的亂數 cmd.Parameters.Add(p); //將準備好的參數加到SqlCommand類別的物件的Parameters集合 conn.Open(); //開啟資料庫連線 string s = cmd.ExecuteScalar().ToString(); //執行查詢,並取得所查到的格言 cmd.Dispose(); //丟棄SqlCommand類別的物件 conn.Close(); //關閉資料庫連線 conn.Dispose(); //丟棄SqlConnection類別的物件 return s; //傳回查詢的結果 } ================ ==程式8 =========== ================ ==程式9 =========== ================ ==程式10 =========== ================ ==程式11 ===========
================ ==程式12 =========== ================ -----box----- 王寧疆 擁有MCSD.NET/MCT認證,目前任職於資策會數位教育研究所台北訓練中心。 -----end-----