我在下面的代码中收到语法错误。"tax_month"
根据我的测试,它来自DateTime
. 我不知道如何以 DateTime 格式插入值。
该字段的架构:
ColumnName: tax_month,
ColumnOrdinal: 0,
ColumnSize: 6,
NumericPrecision: 10,
NumericScale: 0,
DataType: System.DateTime,
ProviderType: 23
这是我的 C# 代码:
string path = @"C:\Purchases\DATA\";
string fileName = "purchase.dbf";
DateTime tax_month = DateTime.FromOADate(41305);
private void button1_Click(object sender, EventArgs e)
{
OdbcConnection dbfConn = new OdbcConnection();
dbfConn.ConnectionString = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;Exclusive=No;Collate=Machine;NULL=NO;DELETED=YES;BACKGROUNDFETCH=NO;SourceDB=" + path;
dbfConn.Open();
OdbcCommand oCmd = dbfConn.CreateCommand(); // needed to query data
oCmd.CommandText = "INSERT INTO " + fileName + " ('tax_month') VALUES ("+tax_month+")";
int inserted = oCmd.ExecuteNonQuery();
dbfConn.Close();
MessageBox.Show("Number of Rows inserted:"+inserted);
}