Agent909
asked on
INSERT INTO tablename gives error
I have two out of five of my tables in a MS Access database not allowing an INSERT INTO statement. It gives me the error:
The Insert Into statement contains the following unknown field name: CurrMonthName.
My SQL statement goes something like this:
"Insert Into DataTable (CurrMonthName,CurrYear) Values (@CurrMonthName,@CurrYear) ;
I've tried deleting the table and re-creating it. I removed the CurrMonthName field in the statement so it's just asking for CurrYear, and I still get the same error, except of course it says the unknown field name = CurrYear. I've also tried inserting the data directly from an Append Query in MS Access, and that won't work either.
Any ideas of what I'm doing wrong?
The Insert Into statement contains the following unknown field name: CurrMonthName.
My SQL statement goes something like this:
"Insert Into DataTable (CurrMonthName,CurrYear) Values (@CurrMonthName,@CurrYear)
I've tried deleting the table and re-creating it. I removed the CurrMonthName field in the statement so it's just asking for CurrYear, and I still get the same error, except of course it says the unknown field name = CurrYear. I've also tried inserting the data directly from an Append Query in MS Access, and that won't work either.
Any ideas of what I'm doing wrong?
ASKER
This is my code, and it works for my other forms:
I will try the code you posted, and get back to you. Thank you!
I will try the code you posted, and get back to you. Thank you!
str = "INSERT INTO DataTraffic " & _
"(CurrMonthName,CurrYear,StoreName,Traffic) " & _
"VALUES (" & _
"@CurrMonthName,@CurrYear,@StoreName,@Traffic)"
myCommand = New OleDbCommand(str, myConnection)
myCommand.Parameters.AddWithValue("@CurrMonthName", obj3.CurrMonthName)
myCommand.Parameters.AddWithValue("@CurrYear", obj3.CurrYear)
myCommand.Parameters.AddWithValue("@StoreName", obj3.StoreName)
myCommand.Parameters.AddWithValue("@Traffic", obj3.Traffic)
What is this:
myCommand.Parameters.AddWi thValue
?
Are you sure this in Access SQL ?
myCommand.Parameters.AddWi
?
Are you sure this in Access SQL ?
ASKER
yes, I'm using it in Access SQL. The OleDbCommand has .Parameters and .AddWithValue.
Sorry ... not really familiar with OleDb ...
Someone will be along ...
mx
Someone will be along ...
mx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
INSERT INTO Table2 ( FIELD1, FIELD2 )
SELECT Table1.FIELD1, Table1.FIELD2
FROM Table1;
Not sure about you @ symbols ...
mx