Solved

SQLBindParameter,SQLExecDirect

Posted on 2001-08-27
5
862 Views
Last Modified: 2007-11-27
I am new to SQLServer.
I am using SQLServer 7.0

I am using C language to call stored Procedure.
My other team mate is using VB6 ADO to call the same SP.
I think calling SP from C will be faster.

I want to call the same SP many Times
I have data in a Text file which i have to send to database


here is my loop
while
     {
         
     fread(szRec,1,402,fp);
         
 iReturn=SQLBindParameter (m_SQLStatement1, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,8 ,0,data, 8, &cbSQL_NTS);

if (iReturn != SQL_SUCCESS)
{
 SQLGetDiagRec (SQL_HANDLE_STMT,m_SQLStatement1,1,theDiagState,&theNativeState,theMessageText,100,&iOutputNo);
     printf("%s",theMessageText);
               
          }
         
          iReturn=SQLBindParameter (m_SQLStatement1, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,2 ,0,data2, 2, &cbSQL_NTS);
          if (iReturn != SQL_SUCCESS)
          {
               SQLGetDiagRec(SQL_HANDLE_STMT,m_SQLStatement1,1,theDiagState,&theNativeState,theMessageText,100,&iOutputNo);
               printf("%s",theMessageText);
               
          }



iReturn = SQLExecDirect(m_SQLStatement1,(SQLCHAR*) "{call ADD_BPMASTER (?,?)}",SQL_NTS);
          if (iReturn != SQL_SUCCESS)
          {
               SQLGetDiagRec(SQL_HANDLE_STMT,m_SQLStatement1,1,theDiagState,&theNativeState,theMessageText,100,&iOutputNo);
               printf("%s",theMessageText);
               
          }

}


this executes only one time .the next time i get the error
Invalid Cursor state.

how to solve the problem


thanks in advance

0
Comment
Question by:v_iyengar
[X]
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
5 Comments
 
LVL 1

Accepted Solution

by:
andymurd earned 50 total points
ID: 6516919
You need to call SQLPrepare (outside of the loop) then SQLBindParameter and then SQLExecute (not SQLExecDirect).

SQLPrepare kind of compiles the SQL so you can bind parameters to it whilst SQLExecute runs the compiled SQL.

Hope this helps,
   Andy.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6862097
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "andymurd" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 

Author Comment

by:v_iyengar
ID: 6863518
now i am not in the project
0
 
LVL 11

Expert Comment

by:griessh
ID: 6867876
What does that mean? Are you still interested in your question or not?

======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6884145
Per recommendation, force-accepted by
Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

705 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