Solved

SQLBindParameter,SQLExecDirect

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

803 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