Solved

SQLBindParameter,SQLExecDirect

Posted on 2001-08-27
5
844 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now