Feb 242017

It’s fairly easy to export all the records that are on your Data Grid View to Excel. The code below shows you how to Run Microsoft Excel Interop and go through each rows and columns in data grid view, and write manually to an Excel worksheet, save the excel file.

The good thing is that you can export anything that you can load into the Data Grid View. The bad thing is that it’s manual dumping of each values in data grid into Excel cells, if you have a lot of data in the grid, it could take a while to populate.

Pre-requisite: to use this, you need to add a new reference to the assembly Microsoft Excel.
Go to Add reference >> COM >> Add “Microsoft Excel 12” or Microsoft Excel 15 depends on the version of Office you have installed.

The dgv_SQL is a DataGridView Control.

if (dgv_SQL.DataSource != null)
                    //this code requires Excel object
                    // go to add reference, COM, Microsoft Excel 12 or 15 object
                    // creating Excel Application
                    Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
                    // creating new WorkBook within Excel application
                    Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
                    // creating new Excelsheet in workbook
                    Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
                    // see the excel sheet behind the program
                    app.Visible = true;
                    // get the reference of first sheet. By default its name is Sheet1.
                    // store its reference to worksheet
                    worksheet = workbook.Sheets["Sheet1"];
                    worksheet = workbook.ActiveSheet;
                    // changing the name of active sheet
                    worksheet.Name = "Any worksheet name here is good";
                    // storing header part in Excel
                    for (int i = 1; i < dgv_SQL.Columns.Count + 1; i++)
                        worksheet.Cells[1, i] = dgv_SQL.Columns[i - 1].HeaderText;
                    // storing Each row and column value to excel sheet
                    for (int i = 0; i < dgv_SQL.Rows.Count - 1; i++)
                        for (int j = 0; j < dgv_SQL.Columns.Count; j++)
                            worksheet.Cells[i + 2, j + 1] = dgv_SQL.Rows[i].Cells[j].Value.ToString();
                    // save the application
                    workbook.SaveAs("c:\\output.xlsx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                    // Exit from the application, app.Quit() will close Excel
                }catch (System.Exception ex)
Feb 232017

By default, you’re not allowed to connect to your MySQL database from other machine.

To enabled that, you first need to set a password to root user in your MySQL Database:

mysqladmin -u root password 'password'

To login to MySQL, use

mysql -u root -p

Once you login to your MySQL, use the following command in MySQL:

GRANT ALL on *.* to 'username'@'localhost' identified by 'password';
Feb 232017

Here’s the simplest way to enable SSH Remote login with Putty to your Ubuntu Linux server.

In your Ubuntu Linux server:

sudo apt-get update
sudo apt-get install openssh-server
sudo ufw allow 22

the first line tells linux to update package
the 2nd line tells Linux to install openssh-server
the 3rd line tells linux firewall to allow access to port 22 (used by Putty).

Now you should be able to remote login to your Ubuntu Linux server by using Putty.

Feb 172017

In Oracle PL/SQL, you can put in your script that would give the user a choice to either go on or quit. The following example gives you a prompt then a user choice of Y or N. Based on the user choice Y or N. Selected block is executed.


SET verify off
select 'Current Audit related Increments in table: ' FROM dual;
select 'Max DATA: ' || max(DATA) from AUDIT_DATA;
select 'Max EVENT: ' || max(EVENT) from AUDIT_EVENT;
accept choice prompt 'Fix Increments for audit (Y/N)?';
    if '&choice' = 'Y' then
        -- update the increments
        update INCREMENTS set LASTVAL = (select max(DATA) from AUDIT_DATA) 
        update INCREMENTS set LASTVAL = (select max(EVENT) from AUDIT_EVENT) 
        update INCREMENTS set LASTVAL = (select max(TRANSACTION) from AUDIT_TRANSACTION) 
        SELECT 'Did not update.' from dual;
    end if;
end ;
SELECT 'Audit related Increments After the fix: ' from dual;
spool off
Feb 012017

To allow others from access an alias directory on your apache server, so you can always login to something like phpmyadmin, or phpsysinfo from outside. You need to update the .conf file for the alias.

the config file is located in your /alias/ folder.

The most important thing is Required all granted, and Allow from all.

After you updated the conf file, need to start apache.

For example, to allow access from remote access to my alias phpmyadmin.conf

Alias /phpmyadmin "E:/wamp64/apps/phpmyadmin4.6.4/"
&lt;Directory "E:/wamp64/apps/phpmyadmin4.6.4/"&gt;
	Options Indexes FollowSymLinks MultiViews
  AllowOverride all
		Require all granted
		Order Allow,Deny
    Allow from all
#   Allow from localhost ::1
# To import big file you can increase values
  php_admin_value upload_max_filesize 128M
  php_admin_value post_max_size 128M
  php_admin_value max_execution_time 360
  php_admin_value max_input_time 360
Sep 042016

Normally, you call the RunWorkerAsync() without an argument to start the background worker. Sometimes you might want to pass some data into the DoWork() function.

All you have to do is simply do:
RunWorkerAsync(some data)

For example, the following code pass an array of string:

string[] list = {"one", "two", "three"};

Then you have to write the receiving code in the DoWork Event function, the trick is in the DoWorkEventArgs e contains the data you passed. You simply use e.Argument, then cast the object into the original type when you passed the data.

For example: the following code receives the string[] list

private void MyBackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
   //get the string[] that was passed by RunWorkerAsync(List)
   string[] myList = e.Argument as string[];
Sep 032016

Normally, you can not set design time property within a user control. Design time means when you drag and drop a user component on your windows form, you can see the properties grid, that allow you to set the properties of a component.

In order to make certain properties of your user control visible in properties grid during design time, you will have to add some attributes to your definition of properties.

For example: this is an example of simple property for a text box, that sets a prompt value.

        [Description("Prompt for entering some text"), Category("Data")]
        public string Prompt
                PromptText = value;
                this.Text = value;
                return this.Text;

Note: you must have a get block for this property, otherwise this property will not show up in design time.

Aug 122016

Sometimes when you try to access UI component from a different thread, you’ll run into exception on you can’t access UI component from a different Thread than the original UI thread that creates the component.

For example, I have a Label, I would like to set the Label1.txt to some text from inside of a backgroundWorker.

Here’s some reference links:

They come up with a very simple way of update any UI component from a different thread.

How to use:
1. Download the following code and place it inside your own project.


2. In the function where you want to update the UI component, invoke this class.

For example:

this.InvokeEx(f =&gt; f.label1.Text = "updating label ...");