一个初级数据库查询语句问题!!再线等!!

qsunxiang 2005-01-05 01:48:37
BOOL CXYZAdo::OpenTable(CString strTable,CString strcolmn)
{
CString strSql;
strSql = "select * from " + strTable+"where Partname="+strcolmn+;
一个数据查询函数,两个参数是表名和查询条件,正确的sql语句怎么写?
...全文
103 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2005-01-05
  • 打赏
  • 举报
回复
Format就是把其他变量转换为字符串
%s表示字符串变量,相当于连接字符串
qsunxiang 2005-01-05
  • 打赏
  • 举报
回复
strSql.Format("select * from %s where Partname='%s'", strTable, strcolmn);
这个方法好用,谢谢!
能简单跟我说一下 format的用法吗?msdn 看不大懂
nastar 2005-01-05
  • 打赏
  • 举报
回复
后边多了个“+”
wuweiadd 2005-01-05
  • 打赏
  • 举报
回复
用ADO的方式连接数据库,最后用_ConnectionPtr 的对象执行和打开SQL语句。我也是刚接触VC和SQL我喜欢用ADO连数据库,比较灵活。
bohut 2005-01-05
  • 打赏
  • 举报
回复
strSql.Format("select * from %s where Partname='%s'", strTable, strcolmn);
wuweiadd 2005-01-05
  • 打赏
  • 举报
回复
_bstr_t strSql;
strSql = "select * from strTable where Partname='"+strcolmn+"';
晨星 2005-01-05
  • 打赏
  • 举报
回复
干脆这样:
strSql.Format("select * from %s where Partname='%s'", strTable, strcolmn);
简洁明了,多好。:P

4,017

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧