Build Errors on SQL Statement
-
First Off, I'm new to code project so if I post something thats already posted sorry. But I'm hoping to find someone who can help out with this build error that I'm receiving on an oledbadapter.insertcommand. I'm loading data into a datagrid for review. After reviewing the data I'm using a sub procedure to load the data into the database from the datagrid. "oledbadapter.InsertCommand(Insert Into table1 from )" error(s): (249): Comma, ')', or a valid expression continuation expected. (249): Property access must assign to the property or use its value. I'm having problems figuring out what to put after the "from" statement. If this is not enough information just let me know and also let me know if I'm posting this right with out being irate about it.
Swish
-
First Off, I'm new to code project so if I post something thats already posted sorry. But I'm hoping to find someone who can help out with this build error that I'm receiving on an oledbadapter.insertcommand. I'm loading data into a datagrid for review. After reviewing the data I'm using a sub procedure to load the data into the database from the datagrid. "oledbadapter.InsertCommand(Insert Into table1 from )" error(s): (249): Comma, ')', or a valid expression continuation expected. (249): Property access must assign to the property or use its value. I'm having problems figuring out what to put after the "from" statement. If this is not enough information just let me know and also let me know if I'm posting this right with out being irate about it.
Swish
Second attempt at this as my connection broke the first time round and IE lost the post.
Swisher24 wrote:
"oledbadapter.InsertCommand(Insert Into table1 from )" error(s): (249): Comma, ')', or a valid expression continuation expected. (249): Property access must assign to the property or use its value.
Okay. The
OleDbDataAdapter
class doesn't have a method calledInsertCommand
(see the class reference on MSDN[^]). It does, however, have a property calledInsertCommand
so your code should read something like this:oledbadapter.InsertCommand = someSqlString
Swisher24 wrote:
I'm having problems figuring out what to put after the "from" statement
Okay, this second part is that you are using an
INSERT
command. You get data "from" a table, you put data "into" a table. You have already specified which table you are putting data "into". See the INSERT Command reference[^] on MSDN. Your command needs to be something along the lines of:INSERT INTO Table1(Column1, Column2, Column3) VALUES ('value1', 'value2', 'value3')
So, you need to specify the columns that the data will be going into and the values of the data. I've not used Data Adapters much (they don't fit most of the applications I've written) so I'm going on 3 year old knowledge that you typically specify the values as a series of parameters. If your database is SQL Server the parameter name is in the format
@paramName
, if you are using Access the parameters are a simple?
placeholder (so remember that the order of the columns must match the order of the columns in the DataTable being passed into the adapter) Does this help?
Upcoming Scottish Developers events: *
-
Second attempt at this as my connection broke the first time round and IE lost the post.
Swisher24 wrote:
"oledbadapter.InsertCommand(Insert Into table1 from )" error(s): (249): Comma, ')', or a valid expression continuation expected. (249): Property access must assign to the property or use its value.
Okay. The
OleDbDataAdapter
class doesn't have a method calledInsertCommand
(see the class reference on MSDN[^]). It does, however, have a property calledInsertCommand
so your code should read something like this:oledbadapter.InsertCommand = someSqlString
Swisher24 wrote:
I'm having problems figuring out what to put after the "from" statement
Okay, this second part is that you are using an
INSERT
command. You get data "from" a table, you put data "into" a table. You have already specified which table you are putting data "into". See the INSERT Command reference[^] on MSDN. Your command needs to be something along the lines of:INSERT INTO Table1(Column1, Column2, Column3) VALUES ('value1', 'value2', 'value3')
So, you need to specify the columns that the data will be going into and the values of the data. I've not used Data Adapters much (they don't fit most of the applications I've written) so I'm going on 3 year old knowledge that you typically specify the values as a series of parameters. If your database is SQL Server the parameter name is in the format
@paramName
, if you are using Access the parameters are a simple?
placeholder (so remember that the order of the columns must match the order of the columns in the DataTable being passed into the adapter) Does this help?
Upcoming Scottish Developers events: *