Sql server 从数据库读取图像并通过web服务发送

Sql server 从数据库读取图像并通过web服务发送,sql-server,database,c#-4.0,Sql Server,Database,C# 4.0,我的数据库中有一个包含系统用户数据的表,其中一个数据是profile picture, 我正在尝试读取这些数据并使用web服务将其发送到智能手机 我尝试了以下代码,但没有成功 public User select(string username, string password) { SqlCommand myCommand = new SqlCommand("select * from users where userName = @uname and

我的数据库中有一个包含系统用户数据的表,其中一个数据是profile picture, 我正在尝试读取这些数据并使用web服务将其发送到智能手机

我尝试了以下代码,但没有成功

        public User select(string username, string password)
    {

        SqlCommand myCommand = new SqlCommand("select * from users where userName = @uname and password = @pwd or email = @uname and password = @pwd");


        myCommand.Parameters.AddWithValue("@uname", username);
        myCommand.Parameters.AddWithValue("@pwd", password);

        DBAccess db = new DBAccess();
        DataSet ds = db.select(myCommand);

        User user = new User();
        DataRow dr;

        try
        {                
            dr = ds.Tables[0].Rows[0];

            user.Id = Convert.ToInt32(dr["userID"]);                
            user.FirstName = (string)dr["firstName"]+" ";
            user.LastName = (string)dr["lastName"] + " ";
            user.Email = (string)dr["email"] + " ";
            user.Username = (string)dr["userName"];
            user.Password = (string)dr["password"];
            user.type = (string)dr["type"];
            user.followingID = Convert.ToInt32(dr["followingID"]);
            user.theme = Convert.ToInt32(dr["theme"]);
            user.tel = (string)dr["tel"] + " ";
            user.mobile = (string)dr["mobile"] + " ";
            user.fax = (string)dr["fax"] + " ";
            user.lastLoggedIn = Convert.ToDateTime(dr["lastLoggedIn"]);
            user.image = Convert.ToByte[](dr["Image"]);

            return user;
        }
        catch (Exception ex)
        {
            DAO.exDao myEx = new DAO.exDao();

            return null;
        }
    }//end of select method
我不知道如何从数据库中读取图像,并将其保存为字节数组,以便发送抛出web服务,因此下面一行出现了错误

user.image = Convert.ToByte[](dr["Image"]);

您可以将图像的路径存储在数据库中。然后,在检索后,您可以显示图像。

亲爱的Fadi Khalil,请定义您的查询以及您希望发送到哪里我已经在上面定义了我的查询,我想从名为“image”的列中读取名为“users”的表中的图像,我想将其保存为字节数组,以便使用web服务发送到iPhone