close

今天要用ASP.NET 取得store procedure返回得值,找了一下資料,終於寫出來了,這是利用store procedure來驗證登入的帳號密碼是否正確,返回值=0代表失敗,=1則是成功

            db_conn connectdb = new db_conn();

            SqlConnection oConn = connectdb.opendb("billing");

            SqlCommand cmd = new SqlCommand("CheckLogin", oConn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@User", SqlDbType.VarChar, 100).Value  = TextBox2.Text.ToString() ;
            cmd.Parameters.Add("@ppwd", SqlDbType.VarChar, 100).Value = TextBox1.Text.ToString();   
         

            try
            {
                oConn.Open();
                int sReturn = Convert.ToInt32(cmd.ExecuteScalar());
                Response.Write("返回值: " + sReturn.ToString());
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                oConn.Close();
            }

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Gino 的頭像
    Gino

    Gino的筆記本

    Gino 發表在 痞客邦 留言(0) 人氣()