我有一个字段是二进制的数据流,想保存入数据库里面。定了一个字段:Msg  varbinary(200)VC++如何往这个里面写入数据呢?我vc里数据是个unsigned char* pMsgData保存的。

解决方案 »

  1.   

    可以直接使用t-sql语句的。
    好像有个writetext/readtext
    还有就是update方法也可以的。
      

  2.   

    或者说,我现在有不定长的码流信息需要保存倒数据里面.那么如何做呢?我想到的就是使用varbinary列保存.比如我现在有一个一系列数据保存
    struct
    {
    int size
    unsigned char* pData
    } data;
    while (1)
    {
     read_data(&data)
     ...........how to save data into SQL DB using ADO connections?
     
    }把这个pData指向的数据保存到数据库表里面,我应该如何做的?请DX指点啊,,,没了方向了.不会做...
      

  3.   

      
    _ConnectionPtr m_pConnection; //连接对象..................//////连接数据库
          //使用记录集来添加记录
          HRESULT hr;
            _RecordsetPtr Record;
            Record.CreateInstance(__uuidof(Recordset));

    try
    {
    hr=Record->Open("select * from UserInformation",//UserInformation表名
                            m_pConnection.GetInterfacePtr(),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    if(SUCCEEDED(hr))
    {   
    try{
    Record->AddNew();
    //写入每个字段
    Record->PutCollect("Msg",_variant_t(pMsgData));
    .........
                                    Record->Update();
    }
    catch(...){
    AfxMessageBox("该用户已存在,无法添加该信息!");
    return;
    }
    }
    }
    catch(_com_error *e)
            {
            e->ErrorMessage();
    return;
    }
    Record->Close();
    Record=NULL;
      

  4.   

    楼上的xd,我这个pMsgData部分是不定长的。你这样子PutCollect("Msg",pMsgData)如何控制存入的数据是什么呢?比如:pMsgData[] = {0x00,0x01,0x03,0x3e,0xff,0x75 .......} 不定长哦。你这样PutCollect,它如何知道应该put多少数据到数据库表呢?