Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Command text was not set for the command object

Posted on 2004-08-30
12
423 Views
Last Modified: 2012-08-14
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
Comment
Question by:harish3699
  • 7
  • 5
12 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11932883
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
 

Author Comment

by:harish3699
ID: 11933047
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11933098
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:harish3699
ID: 11933391
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11933418
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
 

Author Comment

by:harish3699
ID: 11933480
Hi,
I went back to your earlier suggestion. It is only displaying the InsertQuery string.

Harish
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11933514
Okay good. Please show me what the result is here.

FtB
0
 

Author Comment

by:harish3699
ID: 11933522
Hi,

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

Harish
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11933536
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
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 250 total points
ID: 11933564
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
 

Author Comment

by:harish3699
ID: 11935232
Thanks a lot. The second option worked.

Harish
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11935279
Glad to have helped,

FtB
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question