DATASET使用WHERE子句设置SELECT [英] DATASET set SELECT with WHERE clause

查看:731
本文介绍了DATASET使用WHERE子句设置SELECT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,在我的数据访问层中,我有一个使用WHERE子句返回特定字段的方法。



我遇到错误:对象数据源中的数据集不包含任何表格



以下是由于WHERE子句导致错误消息的代码:

Hello, in my data access layer i have a method to return a particular field using WHERE clause.

I encountered an error : Dataset in object data source does not contain any tables

below is the code that results in the error message due to the WHERE clause :

public DataSet getImage(int imageID, String companyID)
        {
            SqlConnection conn;
            StringBuilder sql;
            SqlDataAdapter da;
            DataSet image;

            conn = dbConn.GetConnection();
            image = new DataSet();
            sql = new StringBuilder();
            sql.AppendLine("SELECT * FROM WP_advUploads");
            sql.AppendLine("WHERE imageID=@imageID");
            try
            {
                conn.Open();
                da = new SqlDataAdapter(sql.ToString(), conn);
                da.Fill(image);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }

            return image;
        }



如果我删除WHERE子句,它会显示数据库中的所有信息。我只想要一个具有特定imageID的那个。



任何人都有解决方案吗?


if i remove the WHERE clause, it shows all the information in the database. i only want the one with the specific imageID.

Any one have solution to this?

推荐答案

尝试在_advUploads和WHERE之间放置一个空格,@imageID值来自何处?我的猜测是你想要这样的东西:

Try putting a space between _advUploads and WHERE and where is "@imageID" value coming from? My guess is you want something like this:
sql.AppendLine("SELECT * FROM WP_advUploads ");
sql.AppendLine("WHERE imageID = " + imageID);


这篇关于DATASET使用WHERE子句设置SELECT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆