Solved

SQLBindParameter,SQLExecDirect

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
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.

737 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