2016-07-06 20 views
0

sqliteデータベースに日付と時刻を挿入しようとしていますが、動作していません。sqliteに現在の日付と時刻を挿入する

これは私のDB

CREATE TABLE `bitacora` (
    `id` INTEGER, 
    `log` TEXT, 
    `nombre` VARCHAR(20), 
    `fecha` TEXT 
); 

であり、私は次のクエリをしようとしています。

INSERT INTO bitacora (id, nombre, log, fecha) 
VALUES (1, 'ricardo carreño', 'primer post', (DATETIME('now')); 
+1

どのようなエラーが表示されますか?あなたは私達にこれを伝えるのを忘れた。 –

+0

これは動作しますか?(DATETIME( 'now')) ''? –

+0

@Navoneelうまくいきません。 – esquizoide

答えて

0

varを設定して値リスト内で呼び出さないのはなぜですか。ここで

var DateTime = DateTime.Now; 

私はSQLiteのに挿入しています方法の例です:私のapp.configで

using System.Data.SQLite; 
private void buttonAddNewItemtbl1AddButton_Click(object sender, RoutedEventArgs e) 

{ 
    var tbl1CreatedDateTime = DateTime.Now; 
    { 
     var ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; 

     using (var DbConnection = new SQLiteConnection(ConnString)) 
     { 
      try 
      { 
       const string insertIntotbl1TableString = "INSERT INTO [tbl1] (tbl1ID, tbl1EnvironmentType, tbl1URL, tbl1Server, tbl1CreatedDate, tbl1Deleted) VALUES (@tbl1ID, @tbl1EnvironmentType, @tbl1URL, @tbl1Server, @tbl1CreatedDate, @tbl1Deleted)"; 
       var insertIntotbl1Table = new SQLiteCommand(insertIntotbl1TableString); 

       insertIntotbl1Table.Connection = DbConnection; 

       insertIntotbl1Table.Parameters.AddWithValue("@tbl1ID", Guid.NewGuid().ToString()); 
       insertIntotbl1Table.Parameters.AddWithValue("@tbl1EnvironmentType", ComboBoxtbl1EnvironmentType.Text); 
       insertIntotbl1Table.Parameters.AddWithValue("@tbl1URL", TextBoxtbl1Url.Text); 
       insertIntotbl1Table.Parameters.AddWithValue("@tbl1Server", TextBoxtbl1ServerName.Text); 
       insertIntotbl1Table.Parameters.AddWithValue("@tbl1CreatedDate", tbl1CreatedDateTime); 
       insertIntotbl1Table.Parameters.AddWithValue("@tbl1Deleted", "0"); 

       try 
       { 
        DbConnection.Open(); 
        insertIntotbl1Table.ExecuteNonQuery(); 
        DbConnection.Close(); 
        MessageBox.Show("Successfully added"); 
       } 
       catch (Exception ex) 
       { 
        throw new Exception(ex.Message); 
       } 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     } 
    } 
} 

このように見える:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <connectionStrings> 
    <add name="ConnString" providerName="System.Data.SQLite" connectionString="Data Source=C:\Temp\SQLiteDB.db"/> 
    </connectionStrings> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> 
    </startup> 
</configuration> 
+0

私はsqlite3、exeを使用してデータベースに直接書き込もうとしています。あなたは私とsqlite3で使用する例を与えることができますか? – esquizoide

+0

@esquizoide私はあなたにどのように使用するかの例を与えました –

0

友人が、私は、クエリを修正する助け文。

それは以下のようにすべきである:

INSERTをBitacoraのINTO(ID、ノンブルは、ログ、fecha)VALUES(1、 'リカルドカレーニョ'、 'プライマーポスト'、DATETIME( '今'));

関連する問題