Jesus
Jesus

Reputation: 462

INSERT INTO SQL Server a single value using odbc library with R

I want to insert a single value on SQL table with R using odbc library

To do it, I create the conection, and when it is done, then, I try to insert the data on it, using this comand:

odbc::dbSendQuery(con,"INSERT INTO Datos_Moldeo (Referencia) VALUES ('UNASjkjkjk');")

But this return me this result:

<OdbcResult>
  SQL  INSERT INTO Datos_Moldeo (Referencia) VALUES ('UNASjkjkjk');
  ROWS Fetched: 0 [complete]
       Changed: 1
Warning message:
In new_result(connection@ptr, statement) : Cancelling previous query

What´s happening? What i am doing wrong?

Thanks to all

Upvotes: 3

Views: 839

Answers (2)

Alex Jang
Alex Jang

Reputation: 21

The dbSendQuery function is select queries only. You need to use dbWriteTable or dbSendStatement to write to it.

Upvotes: 2

MKR
MKR

Reputation: 20095

dbSendQuery is driver specific. In some cases it may work but it is not recommended to use for update/insert.

Alternatively you can use dbExecute method.

dbExecute(con,
  "INSERT INTO Datos_Moldeo (Referencia) VALUES ('UNASjkjkjk');")

Upvotes: 1

Related Questions