Tuesday, December 8, 2015

C# when to use ExecuteNonQuery()

ExecuteNonQuery- ExecuteNonQuery does not return any data at all. it is used basically to insert update operationas on table.

C# does Datatable.acceptchanges() save changes to the actual database ?

NO!


http://msdn.microsoft.com/en-us/library/system.data.datatable.acceptchanges.aspx


When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed.
The AcceptChanges method is generally called on a DataTable after you attempt to update the DataSet using the DbDataAdapter.Update method.



So your actual database is unaffected.
 

Sunday, November 1, 2015

C# What are try, catch and finally

Its pretty simple again as the name suggests, 



Remember you shouldn't use a try catch block if you don't expect any errors in the first place

An example of try catch finally would be this;



     try
        {
            int a = 10;
            int b = 20;
            int z = a + b;
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            Console.WriteLine("Executed");
        }