The INSERT INTO
statement contains the following unknown field name:
'
NoName
'. Make sure you have typed the name correctly, and try the operation again.
That is the error thrown when I try to insert a record into a dbase
file (.dbf
) from a .Net
app I am working on.
I use Oledb
connection like this:
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\David\Desktop\Dbase_Files;Extended Properties=dBASE IV;User ID=Admin;Password=");
I had similar issues while selecting. Some columns get returned as 'NoName
' but still with data. I simply use the column index number in place of the column name.
Now I need to insert and it has been a block. Same error comes up with say (when you don't list out the column names):
INSERT INTO [tablename.dbf] VALUES (?, ?, ?);
Sample full code below:
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\David\Desktop\Dbase_Files;Extended Properties=dBASE IV;User ID=Admin;Password=");
connection.Open();
OleDbTransaction trans = connection.BeginTransaction();
OleDbCommand command = new OleDbCommand(@"INSERT INTO [tablename.DBF]
VALUES
(
?, ?, ?
);", connection, trans);
command.Parameters.AddWithValue("param1", 7);
command.Parameters.AddWithValue("param2", "RCN");
command.Parameters.AddWithValue("param3", 0);
try
{
command.ExecuteNonQuery();
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
throw e;
}
finally
{
connection.Close();
}
I have seen forums discuss this when it happens in Ms Access
. But nothing much so far on dbase
. Been thinking it is a driver
thing.
The dbase
file was created by dbase plus (2007)
application.
I found out after a long time that this happened to tables with field-name longer than 8 or 9 characters. When its 10 or more characters long, the field name returns 'NoName'. It sounds ridiculous. When I made the field-name shorter this worked fine.
I got some insight into this here
Now with the fieldnames adjusted, my sample code above works perfectly.