在数据库的特殊列中获取所有项目 [英] Getting all item in a special column of database

查看:201
本文介绍了在数据库的特殊列中获取所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我在将sql server连接到c ++程序方面非常陌生.
我的问题是我只在第一行中返回值的查询
我希望所有行的数据都在特殊列中.

我尝试过的事情:

hi all
I am very new in connecting sql server to c++ program.
My Problem is the query that I run only return value in first row
and I want all rows'' data in special column.

What I have tried:

if (SQL_SUCCESS != SQLExecDirect(hstmt, (SQLWCHAR*)L"SELECT Location FROM dbo.Customers", SQL_NTS)) {
					   		cout << "Error querying SQL Server";
					   		cout << "\n";
					   	}
				   else
				   {
						SQLCHAR sqlVersion[SQL_RESULT_LEN];
						SQLINTEGER ptrSqlVersion;
						while (SQLFetch(hstmt) == SQL_SUCCESS) {
							SQLGetData(hstmt, 2, SQL_CHAR, sqlVersion, SQL_RESULT_LEN, &ptrSqlVersion);
							//display query result
							cout << "\nQuery Result:\n\n";
							cout << sqlVersion << endl;
						}
				   }

推荐答案

您的代码不是打印第一行的值,而是打印每行相同的随机值.

您的查询仅指定一个列.因此,您只能获取第一列的数据,但需要第二列.您在检查GetData()返回值时会注意到这一点.

因此,请尝试以下操作:
Your code is not printing the value of the first row but the same random value for each row.

Your query specifies a single column only. So you can only get data for column one but you are asking for column 2. You would have noticed this when checking the GetData() return value.

So try this:
SQLRETURN ret = SQLGetData(hstmt, 1, SQL_CHAR, sqlVersion, sizeof(sqlVersion), &ptrSqlVersion);
// Check ret here


这篇关于在数据库的特殊列中获取所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆