我在下面的代碼中收到語法錯誤。從我的測試,它來自"tax_month"
這是一個DateTime
字段。我無法弄清楚如何以DateTime格式插入一個值。C#將日期時間插入到DBF文件
模式的那場:
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);
}
非常感謝你,它的工作! – mhar