title: convert datetime to string in sql select query
body: <p>I am trying to display data from database on datagriview and  export data from data grid view to csv, my sqlite database dateformat is DateTime</p>
  
  <pre><code>2012-02-20 16:42:10.000
  </code></pre>
  
  <p>displayed on datagridview is in the format of</p>
  
  <pre><code>20/02/2012 16:42:10 
  </code></pre>
  
  <p>my select statment  is , i want to display on datagridview datetime column as the same format which in database</p>
  
  <pre><code>m_dbConnection.Open();
  
              SQLiteCommand myCommand = new SQLiteCommand();
              myCommand.Connection = m_dbConnection;
  
  
              myCommand.CommandText = "select CompanyId,CONVERT(VARCHAR,DateTime, 103) as date_issued,Serial,ShortDeviceId,MatricolaA,Upper(Targa),VerbaliRuleOnePoints,VerbaliMissedNotificationDescription  from  VerbaliData";
              //myCommand.Connection = myConn;
              DataTable data = new DataTable();
              SQLiteDataAdapter myAdapter = new SQLiteDataAdapter(myCommand);
              //myAdapter.SelectCommand = myCommand;
              myAdapter.Fill(data);
              dataGridView1.DataSource = data;
              this.dataGridView1.Refresh();
              if (dataGridView1.RowCount &gt; 0)
              {
                  string value = "";
                  DataGridViewRow dr = new DataGridViewRow();
                  StreamWriter swOut = new StreamWriter("I:/final test/finaltest12.csv");
  
                  //write header rows to csv
                  for (int i = 0; i &lt;= dataGridView1.Columns.Count - 1; i++)
                  {
                      if (i &gt; 0)
                      {
                          swOut.Write(",");
                      }
                      swOut.Write(dataGridView1.Columns[i].HeaderText);
                  }
  
                  swOut.WriteLine();
  
                  //write DataGridView rows to csv
                  for (int j = 0; j &lt;= dataGridView1.Rows.Count - 1; j++)
                  {
                      if (j &gt; 0)
                      {
                          swOut.WriteLine();
                      }
  
                      dr = dataGridView1.Rows[j];
  
                      for (int i = 0; i &lt;= dataGridView1.Columns.Count - 1; i++)
                      {
                          if (i &gt; 0)
                          {
                              swOut.Write(",");
                          }
                          // Datetime column content transformed in a formatted string....
                          if(i == 1)
                              {
                                object cellValue = dr.Cells[i].Value;
                                    value = (cellValue == DBNull.Value ? 
                                   string.Empty : Convert.ToDateTime(cellValue).ToString("DD-MM-YYYY hh:mm:ss"));
                                   }   
                              value = dr.Cells[i].Value.ToString();
                          //replace comma's with spaces
                          value = value.Replace(',', ' ');
                          //replace embedded newlines with spaces
                          value = value.Replace(Environment.NewLine, " ");
  
                          swOut.Write(value);
                      }
                  }
                  swOut.Close();
              }
  
              m_dbConnection.Close();
          }
  </code></pre>