读书人

help~该怎么解决

发布时间: 2012-01-15 22:57:49 作者: rapoo

help~~~
private void btnAdd_Click(object sender, System.EventArgs e)
{
HttpPostedFile upPhoto=UpPhoto.PostedFile;
int upPhotoLength=upPhoto.ContentLength;
byte[] PhotoArray=new Byte[upPhotoLength];
Stream PhotoStream=upPhoto.InputStream;
PhotoStream.Read(PhotoArray,0,upPhotoLength);

SqlConnection conn=new SqlConnection();
conn.ConnectionString="server=localhost;Database=test;User Id=sa;Pwd=sa";
string strSql="Insert into test(FImage) values(@FImage)";
SqlCommand cmd=new SqlCommand(strSql,conn);
cmd.Parameters.Add("@FImage",SqlDbType.Image);
cmd.Parameters["@FImage"].Value=PhotoArray;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}


报了个byte[]不能转成string 类型的错......
怎么弄啊...高手指点下....

[解决办法]
string strb = System.Text.AscIIEncoding.Deafult.GetString(b);
[解决办法]

探讨
string strb = System.Text.AscIIEncoding.Deafult.GetString(b); //将byte[] 转成 string

[解决办法]
什么地方需要将byte[] 转成 string ,就在哪里加。

读书人网 >C#

热点推荐