private void button1_Click(object sender, System.EventArgs e)
{
MemoryStream stream = new MemoryStream ();
try
{
string sql="";
sql="SELECT * FROM Member WHERE (id = '"+textBox1.Text+"')";
SqlDataReader rs = data_c.openTable_e(sql,data_c.strConnectionString());
if (rs.HasRows)
{
while (rs.Read())
{
//textBox1.Text=rs["id"].ToString();
temp_id=textBox1.Text;
textBox2.Text=rs["M_name"].ToString();
temp_name=rs["M_name"].ToString();
textBox3.Text=rs["M_num"].ToString();
temp_num=rs["M_num"].ToString();;
textBox4.Text=rs["DateTime"].ToString();
textBox5.Text=rs["M_experience"].ToString();
textBox6.Text=rs["M_integral"].ToString();
textBox7.Text=rs["M_balance"].ToString();
textBox8.Text=rs["M_address"].ToString();
textBox9.Text=rs["M_phone"].ToString();
textBox10.Text=rs["M_re"].ToString();
for(int i=0;i<12;i++)
{
member[i]=rs[i+5].ToString();
}
if(rs["logo"]==System.DBNull.Value)
{
MessageBox.Show("logo空");
}
else
{
byte[] blob = (byte[])rs["logo"];
stream.Write (blob, 0, blob.Length);
Bitmap bitmap = new Bitmap (stream,true);
// TODO: Use the bitmap
this.pictureBox1.Image=bitmap;
bitmap.Dispose ();
}
}
chaxun=true;
button2.Enabled=true;
button2.Focus();
}
else
{
MessageBox.Show("没找到会员信息!");
text_null();
chaxun=false;
}
}
catch (SqlException ex)
{
// TODO: Handle the exception
MessageBox.Show(ex.ToString());
}
finally
{
stream.Close ();
}
}未处理的“System.Runtime.InteropServices.ExternalException”类型的异常出现在 system.drawing.dll 中。其他信息: GDI+ 中发生一般性错误。
{
MemoryStream stream = new MemoryStream ();
try
{
string sql="";
sql="SELECT * FROM Member WHERE (id = '"+textBox1.Text+"')";
SqlDataReader rs = data_c.openTable_e(sql,data_c.strConnectionString());
if (rs.HasRows)
{
while (rs.Read())
{
//textBox1.Text=rs["id"].ToString();
temp_id=textBox1.Text;
textBox2.Text=rs["M_name"].ToString();
temp_name=rs["M_name"].ToString();
textBox3.Text=rs["M_num"].ToString();
temp_num=rs["M_num"].ToString();;
textBox4.Text=rs["DateTime"].ToString();
textBox5.Text=rs["M_experience"].ToString();
textBox6.Text=rs["M_integral"].ToString();
textBox7.Text=rs["M_balance"].ToString();
textBox8.Text=rs["M_address"].ToString();
textBox9.Text=rs["M_phone"].ToString();
textBox10.Text=rs["M_re"].ToString();
for(int i=0;i<12;i++)
{
member[i]=rs[i+5].ToString();
}
if(rs["logo"]==System.DBNull.Value)
{
MessageBox.Show("logo空");
}
else
{
byte[] blob = (byte[])rs["logo"];
stream.Write (blob, 0, blob.Length);
Bitmap bitmap = new Bitmap (stream,true);
// TODO: Use the bitmap
this.pictureBox1.Image=bitmap;
bitmap.Dispose ();
}
}
chaxun=true;
button2.Enabled=true;
button2.Focus();
}
else
{
MessageBox.Show("没找到会员信息!");
text_null();
chaxun=false;
}
}
catch (SqlException ex)
{
// TODO: Handle the exception
MessageBox.Show(ex.ToString());
}
finally
{
stream.Close ();
}
}未处理的“System.Runtime.InteropServices.ExternalException”类型的异常出现在 system.drawing.dll 中。其他信息: GDI+ 中发生一般性错误。
是不是存储byte[]的时候没有处理好。
conn.Open();
SqlCommand cmd=new SqlCommand("insert into fuser values ('1a','1b',@i)",conn);
byte[] ib=new Byte[60000];
FileStream fs=new FileStream(@"D:\windows temp\temp\1.jpg",FileMode.Open ,FileAccess.Read );
fs.Read(ib,0,60000);
cmd.Parameters.Add("@i",SqlDbType.Image,(int)fs.Length);
cmd.Parameters["@i"].Value=ib;
cmd.ExecuteNonQuery();
conn.Close();-------------------------------------------------------
//从数据库读图片到pictureboxSqlConnection conn=new SqlConnection(@"data source=chenyuming2004\VSdotNET;uid=sa;pwd=cym;database=lhf");
conn.Open();
SqlCommand cmd=new SqlCommand("select 照片 from fuser where password='1b'",conn);
SqlDataReader reader=cmd.ExecuteReader();
reader.Read();
MemoryStream buf=new MemoryStream((byte[])reader[0]);
Image image=Image.FromStream(buf,true);
pictureBox1.Image=image;
我想问问存的时候是不是有什么说法呀FileStream fs=new FileStream(@"D:\windows temp\temp\1.jpg",FileMode.Open ,FileAccess.Read );我存的时候没有加FileAccess.Read
有关系吗
FileAccess.Read 加上这个参数以后再上传一个就能读出来了
不加这个可能只上传了16b的空流,所以读不出来
不管怎么样了太谢谢你了BearRui(孤熊 | 带你去看海!) 这就结贴