我想关键是找对应的数据类型:
NUMERIC对应的数据类型为:
vartype varaddr SQL Server type of column
NUMERICBIND DBNUMERIC SQLNUMERIC
其中VARTYPE是指DBBIND中连接的类型,VARADDR是指在DB编程中所能用到的变量类型,而SQL SERVER TYPE OF COLUMN指的是SQL SERVER中的数据类型。找好对应的类型就容易取数了。
应用DB_Library,可用这两个函数之一来取得字段值。
RETCODE dbbind (
PDBPROCESS dbproc,
INT column,
INT vartype,
DBINT varlen,
LPBYTE varaddr );
有一例子:
DBNUMERIC xvariable;
DBCHAR yvariable[10];
// Read the query into the command buffer.
dbcmd(dbproc, "select x = 100, y = 'hello'");
// Send the query to SQL Server.
dbsqlexec(dbproc);
// Get ready to process the results of the query.
dbresults(dbproc);
//这两步很重要,在进行BIND前,要指明NUMERIC型变量的精度信息。可用DEFAULTPRECISION和DEFAULTSCALE设置。
xvariable.precision=DEFAULTPRECISION
xvariable.scale=DEFAULTSCALE
// Bind column data to program variables.
dbbind(dbproc, 1, NUMERICBIND, (DBINT) 0, (BYTE *) &xvariable);
dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);
// Now process each row.
while (dbnextrow(dbproc) != NO_MORE_ROWS)
{
// C-code to print or process row data
}
....
还有一函数稍微麻烦:
LPCBYTE dbdata (
PDBPROCESS dproc,
INT column );
// Put the command into the command buffer.
dbcmd(dbproc, "select id from sysobjects");
// Send the command to SQL Server and begin execution.
dbsqlexec(dbproc);
// Process the command results.
dbresults(dbproc);
// Examine the data in each row.
while (dbnextrow(dbproc) != NO_MORE_ROWS)
{
row_number+;
object_id = *((DBINT *)dbdata(dbproc, 1));
printf("row %ld, object id is %ld.\n", row_number, object_id);
}
此例子以整形数据为例,改变数据类型,访问NUMERIC列即可。
以上介绍均可由SQL SERVER BOOK ONLINE获得。