我想使用C++ query从SQL数据库(SQL Server Enterprise)的一列中选择所有二进制数据。我不确定二进制数据中是什么,它所说的是。我试过了(它是传给我学习的),老实说,我在某些部分不是100%理解代码,正如我所评论的那样:
SqlConnection^ cn = gcnew SqlConnection();
SqlCommand^ cmd;
SqlDataAdapter^ da;
DataTable^ dt;
cn->ConnectionString = "Server = localhost; Database=portable; User ID = glitch; Pwd = 1234";
cn->Open();
cmd=gcnew SqlCommand("SELECT BinaryColumn FROM RawData", cn);
da = gcnew SqlDataAdapter(cmd);
dt = gcnew DataTable("BinaryTemp"); //I'm confused about this piece of code, is it supposed to create a new table in the database or a temp one in the code?
da->Fill(dt);
for(int i = 0; i < dt->Rows->Count-1; i++)
{
String^ value_string;
value_string=dt->Rows[i]->ToString();
Console::WriteLine(value_string);
}
cn->Close();
Console::ReadLine();但它只返回大量的"System.Data.DataRow“。
有人能帮我吗?
(在提取二进制数据后,我需要将其转换为矩阵形式,因此,如果有人能为这一部分提供帮助,我将不胜感激!)
发布于 2014-01-28 03:24:57
dt->Rows[i]确实是一个DataRow ^。要从中提取特定字段,请使用其索引器:
array<char> ^blob=dt->Rows[i][0];这将提取第一列(因为您只有一列)并返回它的数组表示。
要回答代码中的问题,SqlDataAdapter的工作方式如下所示:
DataTable来保存要检索的数据。您可以填写它的列,但不是必需的。你也不需要给它一个名字。Fill方法,给它以前创建的DataTable来填充你的查询返回的任何东西。using语句中)。https://stackoverflow.com/questions/21387774
复制相似问题