我自己写了一
void UdbWriteDemo()
{
//加载驱动器
OgdcProviderManager::LoadAllProvider();
UGDataSource* pDS = UGDataSourceManager::CreateDataSource(UGC::UGEngineType::UDB);
if (!pDS) return;
OgdcString strUdbPath = _U("E:\\data\\AAAAA.udb");
OgdcString strAilasName = _U("AAAAA");
OgdcString StrPassWord = _U("");
UGDsConnection &m_connection = pDS->GetConnectionInfo();
m_connection.m_nType = m_nEngineType;
m_connection.m_strAlias = (OgdcString)strAilasName;
m_connection.m_strServer = (OgdcString)strUdbPath;
m_connection.m_strDatabase = (OgdcString)_U("");
m_connection.m_strUser = (OgdcString)_U("");
m_connection.m_strPassword = (OgdcString)StrPassWord;
//创建数据源
if (!pDS->Create())
{
delete pDS;
pDS = nullptr;
AfxMessageBox(IDS_CREATE_DATASOURCE_UDB_FAILED);
return ;
}
//创建Vector dataset
UGDatasetVectorInfo VectorInfo;
VectorInfo.m_strName = _U("AAAAA");
VectorInfo.m_nType = (UGDataset::DatasetType::PointZ);
UGDatasetVector* pVectorDataSet = pDS->CreateDatasetVector(VectorInfo);
if (pVectorDataSet == nullptr) return;
//保持打开
if (!pVectorDataSet->IsOpen())
{
pVectorDataSet->Open();
if (!pVectorDataSet->IsOpen())
{
return ;
}
}
//获取数据记录游标
UGQueryDef pQuery;
UGRecordset* pRecordset = nullptr;
pRecordset = pVectorDataSet->Query(pQuery);
if (pRecordset == nullptr) return;
//属性字段创建
OgdcFieldInfos filedInfos;
filedInfos.AddField(_U("ID"), (OgdcFieldInfo::FieldType::INT32), 0);
filedInfos.AddField(_U("NAME"), (OgdcFieldInfo::FieldType::NText), 128);
if (!pVectorDataSet->CreateFields(filedInfos)) return ;
UGGeoPoint3D geoPoint;
for (int i = 0; i < 4; i++)
{
geoPoint.Make(100.0 + i * 10, 100, 0);
pRecordset->AddNew(&geoPoint);
pRecordset->Edit();
pRecordset->SetFieldValue(UGString(_U("ID")), (UGVariant)(i + 1));
pRecordset->SetFieldValue(UGString(_U("NAME")), UGString(_U("AAAAA")));
pRecordset->Update();
}
pRecordset->Close();
pVectorDataSet->Close();
pDS->Close();
}
个写udb的例子程序,但是写入属性时候总是设置失败,不知道什么原因。
请大神帮忙看看。