• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

Command text was not set for the command object

Hi,
I am getting the following error

Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'

Command text was not set for the command object.

/working/results.asp, line 106

The code is as follows

if mid(Question1,1,9) = "question1"  Then
                Q1Response = mid(Question1,14,1)
                Select Case Q1Response
      Case "1"
                               InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_1) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "2"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_2) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "3"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_3) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "4"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_4) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "5"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_5) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "6"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_6) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "7"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_7) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "8"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_8) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "9"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_9) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      End Select
            
      Set rs1 = Server.CreateObject("ADODB.Recordset")
      rs1.ActiveConnection = MM_dsn1_STRING
      rs1.Source = InsertQuery
      rs1.CursorType = 0
      rs1.CursorLocation = 2
      rs1.LockType = 1
      rs1.Open()


I am getting the error in this following line
rs1.Open()


Please help
Thanks,
Harish
0
harish3699
Asked:
harish3699
  • 7
  • 5
1 Solution
 
fritz_the_blankCommented:
What happens when you do this:

if mid(Question1,1,9) = "question1"  Then
                Q1Response = mid(Question1,14,1)
                Select Case Q1Response
 Case "1"
                               InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_1) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "2"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_2) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "3"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_3) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "4"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_4) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "5"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_5) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "6"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_6) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "7"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_7) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "8"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_8) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case "9"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_9) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     End Select
response.write InsertQuery
response.end

FtB
0
 
harish3699Author Commented:
Hi,
Thanks for the prompt reply.

I dont get the error but the records are not getting inserted into the table in the database.

Thanks,
Harish
0
 
fritz_the_blankCommented:
Okay, that is fine, but think about what just happened here---

we said to write out the result of InsertQuery, but you didn't get anything on your page, did you? That tells us that the Select Case did not capture anything. Try this:

 Select Case Q1Response
      Case "1"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_1) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "2"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_2) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "3"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_3) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "4"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_4) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "5"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_5) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "6"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_6) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "7"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_7) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "8"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_8) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
       Case "9"
              InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_9) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case Else
            Response.write("No matching cases found!")
            Response.end
 End Select
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
harish3699Author Commented:
Sorry, i had a redirect page at the end of the code. That was the reason it was not displaying the InsertQuery. Now, I removed the redirect page and it displays the InsertQuery code. So, i think the select case is capturing data.

Harish
0
 
fritz_the_blankCommented:
Okay, let's go back to my earlier suggestion--which shouldn't have redirected if you did this exactly right:

Select Case Q1Response
     Case "1"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_1) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "2"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_2) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "3"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_3) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "4"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_4) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "5"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_5) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "6"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_6) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "7"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_7) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "8"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_8) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "9"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_9) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case Else
          Response.write("No matching cases found!")
          Response.end
 End Select

response.write ("The query was:" & InsertQuery )
response.end
0
 
harish3699Author Commented:
Hi,
I went back to your earlier suggestion. It is only displaying the InsertQuery string.

Harish
0
 
fritz_the_blankCommented:
Okay good. Please show me what the result is here.

FtB
0
 
harish3699Author Commented:
Hi,

INSERT INTO Political_Results (id, job, date_entered, 1_1) VALUES (5,'jack_lgmt','2004-08-14', 1)

Harish
0
 
fritz_the_blankCommented:
Oh hang on! I am being a complete idiot!!!!!!!!!!!!!!!!!!

If you are doing an update, you won't be able to get a recordset. Your code should be this:

Select Case Q1Response
     Case "1"
          InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_1) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "2"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_2) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "3"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_3) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "4"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_4) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "5"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_5) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "6"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_6) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "7"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_7) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "8"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_8) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
      Case "9"
            InsertQuery = "INSERT INTO Political_Results (id, job, date_entered, 1_9) VALUES (" & current_record & ",'" & job & "','" & t1 & "', 1)"
     Case Else
          Response.write("No matching cases found!")
          Response.end
 End Select

MM_dsn1_STRING.execute(InsertQuery)

FtB
0
 
fritz_the_blankCommented:
If that doesn't work, the do this:

Set objCommand= Server.CreateObject ("ADODB.Command")
objCommand.ActiveConnection = MM_dsn1_STRING
objCommand.CommandText = InsertQuery
objCommand.execute


FtB
0
 
harish3699Author Commented:
Thanks a lot. The second option worked.

Harish
0
 
fritz_the_blankCommented:
Glad to have helped,

FtB
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now