萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> .net編程 >> C#應用存儲過程添加數據之方法

C#應用存儲過程添加數據之方法

class="area">  SqlConnection con = new SqlConnection("Server=(local);database=db_10;Uid=sa;Pwd=");
        con.Open();
        SqlCommand cmd = new SqlCommand("procInsertEmployee", con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter[] prams = {
             new SqlParameter("@員工編號", SqlDbType.VarChar, 50),
                       new SqlParameter("@員工姓名", SqlDbType.VarChar, 50),
                       new SqlParameter("@身份證號", SqlDbType.VarChar, 50),
                                        new SqlParameter("@聯系電話", SqlDbType.VarChar, 50)
    };
        prams[0].Value = TextBox1.Text;
        prams[1].Value = TextBox2.Text;
        prams[2].Value = TextBox3.Text;
        prams[3].Value = TextBox4.Text;
        // 添加參數
        foreach (SqlParameter parameter in prams)
        {
            cmd.Parameters.Add(parameter);
        }
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("<script>alert('注冊成功!')</script>"); 
 
copyright © 萬盛學電腦網 all rights reserved