Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 6 của 6
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Trích dẫn Gửi bởi tientan
    Mã:
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, false)]
        public bool UpdateMonHoc(string tenMonHoc, string maMonHoc)
        {
                QLHS.MonHocDataTable monhocs = Adapter.GetMonHocByMaMonHoc(maMonHoc);
                if (monhocs.Count == 0)
                    // no matching record found, return false
                    return false;
    
                QLHS.MonHocRow monhoc = monhocs[0];
                if (tenMonHoc == null)
    
                    throw new ApplicationException("Name is not null");
                // Update the product record
                int rowsAffected = Adapter.Update(monhoc);
    
                // Return true if precisely one row was updated, otherwise false
                return rowsAffected == 1;


    mình ko hiểu cái lỗi này, mọi người giúp mình với.
    cái tên rỗng rồi(null)

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    [IMG]images/smilies/waiting.gif[/IMG] if (tenMonHoc == null)

    throw new ApplicationException("Name is not null");

    câu lệnh đó của bạn sinh ra lỗi kia mà. Chố đó bạn đừng throw nữa.Thông báo lỗi bằng cách dùng
    if (tenMonHoc == null)
    {
    Response.Write("Name is not null");
    //Response.Write("<script>alert('Name is not null');</script>");
    return false;
    }

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    uh cái tên nó rỗng, thì mình mới ném ra 1 ngoại lệ để thông báo là Name is not null.
    tớ viết trong 1 class mà làm sao mà response chứ.
    với cả mình làm trên VS2008 thì ổn, còn 2010 là bị như vậy

    Mã:
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool UpdateMonHoc(string maMonHoc,string tenMonHoc)
        {
            QLHS.MonHocDataTable monhocs = Adapter.GetMonHocByMaMonHoc(maMonHoc);
            if (monhocs.Count == 0)
                return false;
            if (tenMonHoc == "")
                throw new ApplicationException("Name is not null");
    
            QLHS.MonHocRow monhoc = monhocs[0];
            monhoc.TenMonHoc = tenMonHoc;
    
            int rowAffected = Adapter.Update(monhoc);
            return rowAffected == 1;
        }
    mà khi mà tên tenMonHoc=null thì throw ngoại lệ nó cũng trả lại kiểu false luôn

    Mọi người giúp mình với nhé

  4. #4
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    [IMG]images/smilies/17.gif[/IMG] hix. Respone bình thường thì ko được trong class đó thật. Tuy nhiên, nếu bạn sử dụng API of window thì làm ngon lành luôn. dùng thế này nè:
    [CODE =c#]
    using System.Runtime.InteropServices;
    ..............
    public class Test
    {
    .........
    #region=============Using user32.dll=====================
    [DllImport("User32.dll")]
    //------------------using DLL of window-------------------
    public static extern int MessageBox(int h, String s, String s1, int type);
    #endregion======================================== ===============================
    public void CallFunction()
    {
    Test.MessageBox(0, "hien thi chuoi e:", "thong bao gi day", 0);
    }
    }
    [/CODE]
    Trường hợp of bạn thì không cần dùng kiểu này. Dùng try-catch ở cái chỗ gọi update đó bạn:
    Mã:
    try
    {
       int rowAffected = Adapter.Update(monhoc);
            return rowAffected == 1;
    }
    catch(Exception ex)
    {
    Response.Write("<script>alert('Name is not null');</script>");
     return false;
    }
    thử thế xem ổn ko?

  5. #5
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Gặp lỗi ngoại lệ "applicationException was unhandled by user code" khi throw 1 ApplicationExeption ?

    Mã:
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, false)]
        public bool UpdateMonHoc(string tenMonHoc, string maMonHoc)
        {
                QLHS.MonHocDataTable monhocs = Adapter.GetMonHocByMaMonHoc(maMonHoc);
                if (monhocs.Count == 0)
                    // no matching record found, return false
                    return false;
    
                QLHS.MonHocRow monhoc = monhocs[0];
                if (tenMonHoc == null)
    
                    throw new ApplicationException("Name is not null");
                // Update the product record
                int rowsAffected = Adapter.Update(monhoc);
    
                // Return true if precisely one row was updated, otherwise false
                return rowsAffected == 1;


    mình ko hiểu cái lỗi này, mọi người giúp mình với.

  6. #6
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    giúp mình với mọi người ơi

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •