c#+access多表多条件查询语句怎么写

来源:百度知道 编辑:UC知道 时间:2024/06/27 03:51:33
我数据库里有Topic和User两个表,
Topic的字段有:TopicID,LoginName,Title
User的字段有:UserID,LoginName,UserName,PassWord
连接字段是LoginName
现在我想得到一个包含两个表的所有数据的Dataset,条件是当TopicID=topicid; topicid是个变量,正确的查询语句怎么写,我写了个,不过运行时报错了。哪位帮我写下?
问题已经解决了,我重写了个时对的,应该是这样 sql = "Select [Reply].*,[User].*from [Reply],[User] " + " Where TopicID = " + this._topicID;

string query="select Topic.TopicID,Topic.LoginName,Topic.Title,User.UserID,User.UserName,User.PassWord from Topic Join User on Topic.LoginName=User.LoginName where TopicID='"+topicid"'";
试试看

我的这个不行吗?你试了没有?

string sql = "select ...... where TopiclID =" + topicid;