?
Solved

SQLBindParameter,SQLExecDirect

Posted on 2001-08-27
5
Medium Priority
?
864 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

777 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