【发布时间】:2013-11-17 08:07:21
【问题描述】:
我的数据库中有一个包含系统用户数据的表,其中一个数据是个人资料图片, 我正在尝试读取这些数据并使用网络服务将其发送到智能手机,
我尝试了以下代码,但没有成功
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
我不知道如何从数据库中读取图像并将其保存为字节数组以发送 throw web 服务,所以下一行出现错误
user.image = Convert.ToByte[](dr["Image"]);
【问题讨论】:
-
亲爱的 Fadi Khalil 请定义您的查询以及您想发送到哪里
-
我的查询已经在上面定义了,我想从名为 'Image' 的列中的名为 'users' 的表中读取图像,我想将其保存为字节数组以便使用发送到 iPhone网络服务
标签: sql-server database c#-4.0