Problem With SQLBindParameter

Feb 13, 2007

I am developing an application, using ODBC, that needs to call a stored procedure in an SQL Server DBMS that has a mix of INPUT and INPUT_OUTPUT parameters. I have the code so that there aren't any errors returned from the function calls but I do not see the bound data change after the SQLExecute() function.

Code snippets follow.

CHAR szStatement[256];

CHAR szBuf[256];

SQLINTEGER irval = 0, filenum = 808042, DoNotCall = 0;
SQLVARCHAR vcPhoneNumber[PHONE_LEN];
SQLVARCHAR vcInstanceCode[INSTANCE_LEN] = {0x20};
SQLVARCHAR vcReason[REASON_LEN] = {0x20};
SQLINTEGER rvalLen = 0, fileLen = 0, noCallLen = 10, phoneLen = SQL_NTS, instanceLen = SQL_NTS, reasonLen = SQL_NTS;


lstrcpy( szStatement, "exec ?= some_proc ?, ?, ?, ?, ?" );

sqlr = SQLPrepare( hStmt, szStatement, lstrlen( szStatement ) );
sqlr = SQLBindParameter( hStmt, 1, SQL_PARAM_OUTPUT, SQL_C_LONG, SQL_INTEGER, 10, 0, &irval, 0, &rvalLen );
sqlr = SQLBindParameter( hStmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 10, 0, &filenum, 0, &fileLen );
sqlr = SQLBindParameter( hStmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 10, 0, vcPhoneNumber, 10, &phoneLen );
sqlr = SQLBindParameter( hStmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 50, 0, vcInstanceCode, 0, &instanceLen );
sqlr = SQLBindParameter( hStmt, 5, SQL_PARAM_INPUT_OUTPUT, SQL_C_LONG, SQL_INTEGER, 1, 0, &DoNotCall, 0, &noCallLen );
sqlr = SQLBindParameter( hStmt, 6, SQL_PARAM_INPUT_OUTPUT, SQL_C_CHAR, SQL_VARCHAR, 250, 0, vcReason, 0, &reasonLen );
sqlr = SQLExecute( hStmt );
if( sqlr == SQL_SUCCESS || sqlr == SQL_SUCCESS_WITH_INFO )

{
sprintf( szBuf, "The return value is %d", irval );
sprintf( szBuf, "The file number is %d", filenum );
sprintf( szBuf, "The phone number is %s", vcPhoneNumber );
sprintf( szBuf, "The instance code is %s", vcInstanceCode );
sprintf( szBuf, "The do not call value is %d", DoNotCall );
sprintf( szBuf, "The reason is %s", vcReason );
}

The problem is that in each of the function calls, the sqlr == SQL_SUCCESS but after the call to SQLExecute(), the data does not change for the output parameters. I can do something similar in other query tools that show the proper values but I am not getting the chanes in my bound variables. I tried adding a call to SQLParamData() but I was having a "Function sequence error" problem.



Any help would be very much appreciated. Thanks in advance.

View 10 Replies


ADVERTISEMENT

SQLBindParameter Not Used For All Parameters

Jun 28, 2006

Hi all,
While updating the rows, I encountered the above error. I am using MySql as the database.
And my code is as follow:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ieiprocessConnectionString %>"
ProviderName="<%$ ConnectionStrings:ieiprocessConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM eqpinfo WHERE Server = ?" UpdateCommand="UPDATE EqpInfo SET Eqp_ID = ?,Eqp_Name = ?,Eqp_IP_Address = ?, Eqp_Port = ?, Server = ?, IEI_Local_IP = ?, Area = ?, Sub_Area = ?, Stocker_ID = ? WHERE Item = ?">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Server" PropertyName="SelectedValue"
Type="String" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
 
for (int i = 1; i <= rowsCount; i++)
{
GridView1.UpdateRow(i, false);
}
Can anyone point out to me what is my error?
All fields are text except Item is autoincrement number.
Thanks
 

View 1 Replies View Related

SQLBindParameter WCHAR 20 To 3145778?

May 9, 2007



Hello,



I use ODBC API to insert records into database with storage procedure (sql server 2k5) , the field in table is ntext type.

Use SQLBindParameter to bind a wchar parameter.
there is a void* pValue point to the wchar string,

In memory window in vc++ IDE, the vlaues is 2.0. ( wide char for 20)

I use sql profiler to monitor the sql statement :

exec mystorageprocedure N'3145778'

"20" is chanaged to "3145778"
I didn't understand why the convertion happen?
any advise ?



Thanks
Robert

View 6 Replies View Related

SQLBindParameter SQL_C_TYPE_DATE HY003 Error

Jun 5, 2006

I'm trying to use ODBC to send data to SQL Server from VC++. When I try to setup the parameters for sending a date to the database by calling SQLBindParameters(), I get the error HY003 "Program type out of range".

This indicates that the 4th parameter, ValueType, is not correct. But I'm hard coding it to a known valid value. Actually, I'm copies code strait from the Microsoft Help and still getting this error.

Specifically, here's the lines of code:

DATE_STRUCT dsOpenDate;
SQLINTEGER cbOpenDate = 0;
SQLBindParameter (hstmt, 3, SQL_PARAM_INPUT, SQL_C_TYPE_DATE, SQL_TYPE_DATE, 0, 0, &dsOpenDate, 0, &cbOpenDate);

NOTE: This is from the sample in MS Help page:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2005OCT.1033/odbc/htm/odbcsqlbindparameter.htm

So, according to the error, SQL_C_TYPE_DATE is not valid. But since it's hard coded here, it must be valid. What gives?

Any help would be appreciated,

Scott

View 9 Replies View Related

Yet Another SQLBindParameter Thread -- Char* As A Parameter? (already Did A Search)

May 3, 2007

Hi guys, first post here. It's been a few years since I've worked with ODBC, so I'm a bit rusty. I'm having trouble figuring out how to use a char* string as a parameter for a SELECT statement. I'm trying to compare the contents of a varchar column (with size=20) against the string.

Here's the code that I'm using:


char* arg;
SQLINTEGER stringSize = 32;

retcode = SQLBindParameter(hstmt,
1,
SQL_PARAM_INPUT,
SQL_C_CHAR,
SQL_VARCHAR,
20,
0,
arg,
stringSize,
&stringSize);

retcode = SQLPrepare(hstmt,
(SQLCHAR*) "SELECT * "
"FROM myTable "
"WHERE (stringColumn = '?')",
SQL_NTS);

retcode = SQLExecute(hstmt);

retcode = SQLFetch(hstmt);

When SQLFetch() runs, it returns 100 (SQL_NO_DATA). If I type the query manually into my Enterprise Manager console, I get several results, so I know the query is correct. Any idea what I might be doing wrong with the ODBC calls?

Thanks!

View 1 Replies View Related

SQLBindParameter, SQL_C_WCHAR, And SQL_WLONGVARCHAR, Am Not Sure What Information That I Should Be Passing.

Jun 26, 2007

As the title states, I am using SQLBindParameter with SQL_C_WCHAR and SQL_WLONGVARCHAR as two of the parameters. I am getting incorrect scale error (I can cause it to occur again if someone needs the actual error) when passing the cbColDef of LONG_MAX and -1 for ibScale (see the header file for these variables). These are the values retrieved from the column definition. Also ibScale should be ignored, given the type. Is cbColDef the size in characters or bytes for this given type?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved