2014-03-12 5 views
0

Windows 응용 프로그램을 사용하고 sqlite에서 datagriview 테이블 데이터를 표시하고 있지만 표시하는 동안 내 날짜 형식이 변경되는 이유를 이해할 수 없습니다. DataGridview 테이블 데이터 표시

SQLite는 날짜 형식 DateTime 2012-02-20 16:42:10.000

DataGridView에 날짜 형식 20/02/2012 16:42:10

내 코드

SQLiteConnection m_dbConnection; 

m_dbConnection = new SQLiteConnection("Data source = F:/Explor/final test/WebMobility.db; Version=3;"); 

m_dbConnection.Open(); 

SQLiteCommand myCommand = new SQLiteCommand(); 
myCommand.Connection = m_dbConnection; 


myCommand.CommandText = "select CompanyId,DateTime,description from VerbaliData"; 

DataTable data = new DataTable(); 
SQLiteDataAdapter myAdapter = new SQLiteDataAdapter(myCommand); 

myAdapter.Fill(data); 
dataGridView1.DataSource = data; 
this.dataGridView1.Refresh(); 
if (dataGridView1.RowCount > 0) 
{ 
    string value = ""; 
    DataGridViewRow dr = new DataGridViewRow(); 
    StreamWriter swOut = new StreamWriter("F:/Explor/final test/finaltest12.csv"); 

    //write header rows to csv 
    for (int i = 0; i <= dataGridView1.Columns.Count - 1; i++) 
    { 
     if (i > 0) 
     { 
      swOut.Write(","); 
     } 
     swOut.Write(dataGridView1.Columns[i].HeaderText); 
    } 

    swOut.WriteLine(); 

    //write DataGridView rows to csv 
    for (int j = 0; j <= dataGridView1.Rows.Count - 1; j++) 
    { 
     if (j > 0) 
     { 
      swOut.WriteLine(); 
     } 

     dr = dataGridView1.Rows[j]; 

     for (int i = 0; i <= dataGridView1.Columns.Count - 1; i++) 
     { 
      if (i > 0) 
      { 
       swOut.Write(","); 
      } 

      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(); 

답변

0

, SqlLite가 절약 날짜 시간 형식에서 범용 포맷 및 보조의 호출이 2 가지가 있습니다 모든 응용 프로그램. 이 정보는 지역화 문제를 방지하는 데 도움이됩니다. sqlite 날짜 형식 DateTime 2012-02-20 16 : 42 : 10.000

DataGrid는 시스템 형식 (DD/MM/YYYY)을 선택하기 때문에이를 표시합니다. 동일한 형식으로 표시해야하는 경우 필요합니다. 분명히 선언하는 것이다. 예 : Date.ToUniversalTime() datagridview 날짜 형식 20/02/2012 16:42:10

+0

나는 내 컴퓨터에서 datetime 시스템을 변경했기 때문에 감사의 말을 많이했습니다. – smrithi

0

데이터베이스는 항상 yyy-MM-dd 형식으로 저장됩니다. DatGrid의 날짜는 컴퓨터 날짜 형식에 따라 형식을 표시합니다.

아래의 예를 보면 알 수 있습니다. 결과는 당신이 Format 기능으로 변경할 수 있습니다 2014-03-12 14:50:45.450

select FORMAT(GETDATE(),'dd/MM/yyy'); 

아래처럼 현재 날짜를 얻을 수 있도록 데이터베이스를 쿼리합니다.

select FORMAT(GETDATE(),'dd/MM/yyy'); 

다음과 같이 쿼리를 변경하면 문제가 해결됩니다.

select CompanyId, FORMAT(GETDATE(),'yyy-MM-dd hh:mm:ss'), description from VerbaliData;