应该怎么给List Control里面写数据啊
为什么我只能写一列啊
再就是能不能给利用ADO连接SQLSEVER的代码啊?

解决方案 »

  1.   

    要首先用InsertItem插入一行,然后在用SetItemText再插哪一列的数据
     HRESULT hr;
        _ConnectionPtr m_pConnTemp = theApp.m_pConnection; UpdateData();
    CString strConnection="Provider=SQLOLEDB.1;Data Source=127.0.0.1;Initial Catalog=zviewrecord;User ID=sa;PWD=123";
    try
    {
    hr = m_pConnTemp.CreateInstance("ADODB.Connection"); if(SUCCEEDED(hr))
    {

    hr=m_pConnTemp->Open((_bstr_t)strConnection,"","",-1);
    AfxMessageBox("Sucess!");

    }
    }
    catch(_com_error e)
    {
    m_pan=false;
    GetDlgItem(IDC_InsertDataBase)->EnableWindow(false);
    CCommon common;
    AfxMessageBox(common.DisplayAdoError(m_pConnTemp));
    }  
    if (m_pConnTemp != NULL)
    {
    if (m_pConnTemp->State)
    {

    if (theApp.m_pConnection != NULL)
    {
    if (theApp.m_pConnection->State)
    {
    theApp.m_pConnection->Close ();
    }
    }
    theApp.m_pConnection = m_pConnTemp;
    }
    }
    127.0.0.1是连接本地的sql sever,用户名是sa,密码是:123,zviewrecord是初始的库名
    若连其他的机子就用他的IP 好了
      

  2.   

    使用顺序:
      SetExtendedStyle( DWORD dwNewStyle );设置风格
      InsertColumn( int nCol, const LVCOLUMN* pColumn );插入列
      InsertItem( int nItem, LPCTSTR lpszItem, int nImage );插入行和设置第一列内容
      SetItemText( int nItem, int nSubItem, LPTSTR lpszText );设置后面列的内容
      DeleteItem( int nItem ); 或 DeleteAllItems( );删除行
      DeleteColumn( int nCol );删除列函数使用详见msdn