Results 1 to 3 of 3

Thread: when i press finilize the button its show me error of btnfinilize

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    19

    when i press finilize the button its show me error of btnfinilize

    Code:
                string insertsupplierinvoice = string.Format("insert into SupplierInvoiceTable(Supplier_ID, User_ID, InvoiceNo,Title,TotalAmount,InvoiceDate,Description) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                    supplierid, CurrentUser.UserID, invoiceno, pruchasetitle, totalpurchaseamount, DateTime.Now.ToString("yyyy/MM/dd HHmmss"), "");
                bool result = DatabaseAccess.Insert(insertsupplierinvoice);
                if (result == false)
                {
                    ep.SetError(btnFinilize, "Please Check Purchase Info in finilizeing some to issue!");
                    btnFinilize.Focus();
                    return;
                }
    
    

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: when i press finilize the button its show me error of btnfinilize

    First of all, how about you do us the courtesy of making your code easy to read?
    Code:
    string insertsupplierinvoice = string.Format("insert into SupplierInvoiceTable(Supplier_ID, User_ID, InvoiceNo,Title,TotalAmount,InvoiceDate,Description) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                                                 supplierid,
                                                 CurrentUser.UserID,
                                                 invoiceno,
                                                 pruchasetitle,
                                                 totalpurchaseamount,
                                                 DateTime.Now.ToString("yyyy/MM/dd HHmmss"),
                                                 "");
    bool result = DatabaseAccess.Insert(insertsupplierinvoice);
    
    if (result == false)
    {
        ep.SetError(btnFinilize, "Please Check Purchase Info in finilizeing some to issue!");
        btnFinilize.Focus();
        return;
    }

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: when i press finilize the button its show me error of btnfinilize

    As for the issue, of course you do, because that is exactly what your code is telling it to do. Obviously result must be false if you see that error message, so DatabaseAccess.Insert must be returning false. As you've provided us with no information about that method, how could we tell you what's wrong? You need to debug that method yourself to find out WHY it's returning false. If you discover that the issue is with the SQL code then you need to actually look at the SQL code, not just the C# code that builds it.

    You should also learn how to do data access properly, using parameters. Inserting values into SQL code using string concatenation is fraught and may be the root of the issue here. Don't do it. You can follow the Blog link in my signature below to find a post on Parameters In ADO.NET.

    Finally, as the documentation states, don't call Focus on a control. The proper option for an application developer is to call Select.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width