ADODC : Operation is not allowed when the object is closed

Error trying to execute INSERT query in ADODC

Page 1 of 1

7 Replies - 13871 Views - Last Post: 19 March 2009 - 02:05 AM Rate Topic: -----

#1 jurasekpeter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 09

ADODC : Operation is not allowed when the object is closed

Posted 15 March 2009 - 11:29 AM

Hi,

I am trying to create a program which will access a MySQL dbase, not only read data, I will need to manipulate data.

I have tried to find out how it works but found a problem. This is my code

Private Sub CmdExecuteQuery_Click()
  Dim sql As String
  sql = TxtQuery.Text
  Adodc1.CommandType = adCmdText
  Adodc1.RecordSource = sql
  Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1
End Sub



On the form I have a ADODC object and a DataGrid.
The variable sql holds the query, whe I execute a SELECT query - NO PROBLEM. When I execute a INSERT query I will get the message "Operation is not allowed when the object is closed" on the line "Adodc1.Refresh" but the query will be executed. What am I doing wrong???

This post has been edited by jurasekpeter: 15 March 2009 - 11:31 AM


Is This A Good Question/Topic? 0
  • +

Replies To: ADODC : Operation is not allowed when the object is closed

#2 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

Re: ADODC : Operation is not allowed when the object is closed

Posted 16 March 2009 - 02:34 AM

View Postjurasekpeter, on 15 Mar, 2009 - 10:29 AM, said:

Hi,

I am trying to create a program which will access a MySQL dbase, not only read data, I will need to manipulate data.

I have tried to find out how it works but found a problem. This is my code

Private Sub CmdExecuteQuery_Click()
  Dim sql As String
  sql = TxtQuery.Text
  Adodc1.CommandType = adCmdText
  Adodc1.RecordSource = sql
  Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1
End Sub



On the form I have a ADODC object and a DataGrid.
The variable sql holds the query, whe I execute a SELECT query - NO PROBLEM. When I execute a INSERT query I will get the message "Operation is not allowed when the object is closed" on the line "Adodc1.Refresh" but the query will be executed. What am I doing wrong???

Quote

It is because inside your CmdExecuteQuery_Click(),
there is no connection on your database. You must open a connection before you execute a query. And close it after the execution.

Was This Post Helpful? 0
  • +
  • -

#3 jurasekpeter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 09

Re: ADODC : Operation is not allowed when the object is closed

Posted 16 March 2009 - 10:22 AM

Quote

It is because inside your CmdExecuteQuery_Click(),
there is no connection on your database. You must open a connection before you execute a query. And close it after the execution.



How? I am not using an ADO object, the Adodc1 is a control on the form

This post has been edited by jurasekpeter: 16 March 2009 - 10:23 AM

Was This Post Helpful? 0
  • +
  • -

#4 sastre06  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 81
  • Joined: 05-June 07

Re: ADODC : Operation is not allowed when the object is closed

Posted 16 March 2009 - 07:06 PM

Quote

How? I am not using an ADO object, the Adodc1 is a control on the form


In my opinion, why not use ADODB connection, it will be easier to use.
Was This Post Helpful? 0
  • +
  • -

#5 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

Re: ADODC : Operation is not allowed when the object is closed

Posted 16 March 2009 - 07:28 PM

View Postjurasekpeter, on 16 Mar, 2009 - 09:22 AM, said:

Quote

It is because inside your CmdExecuteQuery_Click(),
there is no connection on your database. You must open a connection before you execute a query. And close it after the execution.



How? I am not using an ADO object, the Adodc1 is a control on the form

Quote

Instead of using ADODC why not use ADODB. Because in ADODB you can establish a connection dynamically. The problem in using ADODC if you change the location of your database or change the database itself it will cause a connetion problem. In this case I think you must practise first using ADODB. When I'm just new in VB6 I only use ADODC once and switch on ADODB.

Was This Post Helpful? 0
  • +
  • -

#6 jurasekpeter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 09

Re: ADODC : Operation is not allowed when the object is closed

Posted 17 March 2009 - 01:49 AM

You both are absolutely right :^: I have tried ADODB instead ADODC and it is very easy to do anything :D Forget about ADODC!!! Long lives ADODB!!!

But what is the advantage of ADODC when you can do it much easier in ADODB??

Doesn't matter, thank you both
Was This Post Helpful? 0
  • +
  • -

#7 sastre06  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 81
  • Joined: 05-June 07

Re: ADODC : Operation is not allowed when the object is closed

Posted 18 March 2009 - 02:17 AM

Quote

But what is the advantage of ADODC when you can do it much easier in ADODB??


difference of ADODB and ADODC

ADODC is the way of connecting to database through ADO component.
ADODB is the way of connecting to database in the way of coding.
Was This Post Helpful? 0
  • +
  • -

#8 jurasekpeter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 09

Re: ADODC : Operation is not allowed when the object is closed

Posted 19 March 2009 - 02:05 AM

yes that is true but what is the advantage of using ADODC?? Is there something what you can do with ADODC and not with ADODB??
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1