private void update()


            Int64 sum = 0;
            sum = (!string.IsNullOrEmpty(Request.QueryString["Id"])) ? Int64.Parse(Request.QueryString["Id"]) : 0;

            if (sum != 0) - Here in Debug mode, i get this condition is false and equals 0
            {
                var context = new myDatabase();

                var s = context.myTableName.FirstOrDefault(c => c.Id == sum);

                if (s!= null && s.Id > 0)
                    {
                        if (!String.IsNullOrEmpty(myTextBoxId.Text))
                        {
                            MyUpdateMethod(sum,Decimal.Parse(myTextBoxId.Text));
                        }
                    }

                    else
                    {
                        if (!String.IsNullOrEmpty(myTextBoxId.Text))
                        {
                            MyInsertMethod(sum, Decimal.Parse(myTextBoxId.Text));
                        }

                    }

                    Dear Friends,

                    I just want a if else condition to update (in if) and insert (in else) my Database table. But Using above condition, my Table only get Inserted and updates doesn't work. What's wrong in my code. Assigning null to my variable is correct? Pls do your help for me.

                    Thanks in advance

Recommended Answers

All 3 Replies

Please provide the exact error message and the code that is highlighted when the error occurs.

If I unsertood well your issue, the sentence Request.QueryString["Id"] is returninng a null or empty string or a zero value.
Please, verify what is the real content of the requested string.

Hope this helps

Thank you friends for your replies. I just complicated myself. I has some issues in my Linq Select Query. Just i modified my column name and it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.