连接字符串:
_bstr_t strConnect="Provider=SQLOLEDB.1;Initial Catalog=“数据库名称”;Data Source=远程IP";
2:使用ADO DATA的ActiveX控件
步骤1:
这个ADO控件的连接字符串的use connection string下的完整内容:
Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=LibraryManageSys;Data Source=127.0.0.1
使用代码连接数据库:
BOOL CActiveXDBDlg::OnInitDialog()
{
……
m_adodc.SetConnectionString("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=suntest;Data Source=WWW-ED1F301E78B;Persist Security Info=False");
CString sql = "select * from 仓库3 order by 仓库编号 desc";
m_adodc.SetRecordSource(sql);
m_adodc.Refresh();
m_grid.SetRefDataSource(m_adodc.GetControlUnknown());
……
return TRUE;
}
步骤2:
步骤3:
完整内容:
SELECT s.SpeId, s.Name AS 专业名称, d.DepName AS部门, s.Describes AS描述 FROM Speciality s, DepInfo d WHERE s.DepId = d.DepId
步骤4:
注意:caption内容为ado data控件的caption名字